Examples

Closures

A returned lambda is a record the compiler writes.

main (print)

# A function can return a lambda. What comes back is a record the
# compiler writes, holding what was captured, with the body as its code.
makeAdder(amount int) (int -> int)
    (x int: x + amount)

scale(factor int) (int -> int)
    (x int: x * factor)

main()
    addFive = makeAdder(5)
    triple = scale(3)
    a = addFive(1)
    b = triple(addFive(2))
    print.line("{a} {b}")
6 21