A code generation library for Gleam
2

Configure Feed

Select the types of activity you want to include in your feed.

Gleam 93.9%
Other 6.1%
49 1 0

Clone this repository

https://tangled.org/gearsco.de/trick https://tangled.org/did:plc:x5gxakgsszy2kmmkmcipry33
git@tangled.org:gearsco.de/trick git@tangled.org:did:plc:x5gxakgsszy2kmmkmcipry33

For self-hosted knots, clone URLs may differ based on your setup.



README.md

trick#

Package Version Hex Docs

trick is a code generation library for Gleam, based on elm-codegen.

It's designed to assist any library or application which needs to generate Gleam code. The generated code is fully type-checked, so you can be sure that it will compile correctly once generated.

trick is currently in development and not yet published on Hex. You can add it as a git dependency in your gleam.toml:

[dependencies]
trick = { git = "https://github.com/GearsDatapacks/trick.git", ref = "main" }

Then, start generating code:

import trick
import simplifile

pub fn main() {
  let assert Ok(code) = trick.to_string({
    use pi <- trick.constant("pi", trick.Private, trick.float(3.14))
    use circle_area <- trick.function("circle_area", trick.Public, {
      use radius <- trick.parameter("radius", trick.float_type())
      trick.function_body({
        use radius_squared <- trick.variable(
          "radius_squared",
          trick.multiply_float(radius, radius),
        )
        trick.expression(trick.multiply_float(radius_squared, pi))
      })
    })
    trick.end_module()
  })

  let assert Ok(Nil) = simplifile.write("out.gleam", code)
}

Until publication on Hex, documentation can be found at https://gearsco.de/trick.