Documentation channel: current development main at compiler checkpoint 1d7e15e. The latest tagged release is v0.0.3; pages identify APIs that are not yet released.

Functions & lambdas

Functions have explicit return types. Lambdas are first-class callable values and may infer parameter types from context.

Named functions

function multiply(double a, double b) -> double {
    return a * b;
}

Void functions

function announce() -> void {
    print("ready");
    return;
}

Function values

function<(double, double) -> double> op := multiply;
result := op(2.0, 4.0);

Lambdas

The common case leaves the callable type to inference.

square := (x) => x * x;

Block-bodied lambdas

clamp := (x, lo, hi) => {
    if (x < lo) { return lo; }
    if (x > hi) { return hi; }
    return x;
};

Typed lambda values

function<(double, double) -> double> multiply :=
    (a, b) => a * b;

Parameters may also carry explicit composite types when the callable context does not provide them.

read := (int& value, string[] labels) => *value;

Nested callable types

include <map>;

function main() -> int {
    map<string, int[]> groups;
    vector<function<(int)->int>> operations := [];
    function<(map<string, int[]>, int)->int> count :=
        (map<string, int[]> values, int fallback) => fallback;
    return 0;
}

Closures

Escaping closures capture values safely. The compiler keeps the closure lifetime independent from the lexical stack frame that created it.

factor := 3;
scale := (x) => x * factor;
print(scale(4));