gen_core_erlang

Types

pub type Clause
pub type Definition =
  #(FunctionDecl, Function)

Type that wraps the various c_erl() subtypes into an expression. These expressions are used as function bodies, in case clauses after ->.

pub opaque type Expression
pub opaque type Function

Type that wraps name and arity, such as loop/1.

pub type FunctionDecl
pub type ModuleAttribute

Outermost Core Erlang term that can be passed to compile:forms(mod, [from_core]).

pub type ModuleDef

Type that wraps the various c_erl() subtypes into a pattern. These patterns are used as function arguments, in case clauses before ->,

pub opaque type Pattern

Functions

pub fn c_apply(
  f_def: FunctionDecl,
  arguments: List(Expression),
) -> Expression
pub fn c_apply_anonymous(
  function: Expression,
  arguments: List(Expression),
) -> Expression

Call a function, but not by name. Most likely, the function has been assigned to a variable

c_let([p_var("Fun")], f2e(c_fun(...)), c_call_anonymous(c_var("Fun", [])))
pub fn c_atom(name: String) -> Expression

Create an expression for the atom that has string representation name

pub fn c_binary(string: String) -> Expression

Create an Erlang binary for a Gleam string. Currently, there is no way to generate other binaries

pub fn c_call(
  module: String,
  name: String,
  arguments: List(Expression),
) -> Expression

Call an exported function

pub fn c_case(
  expr: Expression,
  clauses: List(Clause),
) -> Expression
pub fn c_clause(
  patterns: List(Pattern),
  expr: Expression,
) -> Clause

A single clause for a c_case. Although you can pass a list of patterns, it seems expr always returns one value

pub fn c_clause_w_guard(
  patterns: List(Pattern),
  guard: Expression,
  expr: Expression,
) -> Clause

Although we use the type Expression, you should only pass those allowed in guards. Maybe some day we can enforce this with a type, but that seems very hard

pub fn c_cons(head: Expression, tail: Expression) -> Expression

Concatenate two expressions. As per Erlang, the tail argument does not have to be a list. If you want to generate an empty list, use c_nil, if you want to generate a list from 1 or more items, use make_list

pub fn c_float(value: Float) -> Expression
pub fn c_fname(name: String, arity: Int) -> FunctionDecl

Create a function ‘name’ such as “loop/1”. To be used in module definitions (both exports and functions) as well as local function application

pub fn c_fun(
  arguments: List(Pattern),
  body: Expression,
) -> Function

If you need this as an Expression, use f2e

pub fn c_int(value: Int) -> Expression
pub fn c_let(
  variables: List(Pattern),
  argument: Expression,
  body: Expression,
) -> Expression

Equivalent to

<P1, ..., Pn> = argument
body

where you can use a pattern line p_int("Num") by its variable `c_int(“Num”)

Note that all Pi need to be p_var patterns. If you need other matches, use c_case with a single c_clause

pub fn c_module(
  name: String,
  exports: List(FunctionDecl),
  attributes: List(ModuleAttribute),
  definitions: List(#(FunctionDecl, Function)),
) -> ModuleDef

There should be a definition for each export. Other definitions are local functions. Note: For attributes, you currnely have to pass an empty list.

pub fn c_nil() -> Expression

Erlang’s empty list.

pub fn c_receive(clauses: List(Clause)) -> Expression
pub fn c_seq(arg: Expression, body: Expression) -> Expression

Execute two expression consecutively. Erlang functions always return a result. If you need that result, use c_let. If you want to execute more than 2 expressions, use:

let assert Ok(expr) = list.reduce(expressions, c_seq)
pub fn c_tuple(values: List(Expression)) -> Expression
pub fn c_var(name: String) -> Expression
pub fn f2e(f: Function) -> Expression
pub fn list_elements(list: Expression) -> List(Expression)

Unspecified behaviour. Used for testing this library.

pub fn make_list(expressions: List(Expression)) -> Expression

Convenience function, equivalent to

c_cons(expr_1, .... c_cons(expr_n, c_nil()))
pub fn p_atom(name: String) -> Pattern

Create a pattern for the atom that has string representation name

pub fn p_cons(head: Pattern, tail: Pattern) -> Pattern
pub fn p_float(value: Float) -> Pattern
pub fn p_int(value: Int) -> Pattern
pub fn p_nil() -> Pattern
pub fn p_tuple(values: List(Pattern)) -> Pattern
pub fn p_var(name: String) -> Pattern
Search Document