Functions and examples
Header
Section titled “Header”fn NAME PARAM* -> TYPEPARAM := name:TYPEfn add a:i64 b:i64 -> i64 ex add 2 3 = 5 + a bBody lines, in order
Section titled “Body lines, in order”doc "text": optional, at most one. States intent, does not affect execution.ex EXPR = EXPR: examples. At least one is required for every function exceptmainand functions that call effectful builtins.- Statements:
let NAME EXPRbinds a value (immutable, no shadowing),do EXPRevaluates an expression of typeunitfor its effect. - One final line: the result of the function.
fn fib n:i64 -> i64 doc "nth fibonacci number" ex fib 0 = 0 ex fib 10 = 55 if < n 2 n + fib - n 1 fib - n 2Examples are tests
Section titled “Examples are tests”aleph check and aleph test run every ex line. A failing example is E002, with the expected and actual values; a missing one is E001. Examples run hermetically: they see only global definitions, file access is denied and output is discarded.
main takes no parameters and returns unit or res unit str. If it returns err e, Tlön prints e to stderr and exits with code 1.