Functions and lists
Give a function typed inputs and a return type, then call it by name.
Call functions with XML
An XML tag calls a function with named arguments. The function can return any type.
- A bare
activesuppliestrue. Omitting aBoolargument suppliesfalsein XML. Useactive={expression}for a computed value. - A numeric argument can use
numeric-1,numeric--1for negative values, or a unit such aswidth-24pt. - A string-literal choice can use
mode-short. For an unrestrictedString, writelabel="Take". - Style utilities use the same parameter names. For example,
w-24can supply a user-defined function'swidthargument in points.
Put nested content between the tags to pass it as the children list. Plain text in an element list becomes a Text element. Use braces such as {"hello"} to pass a string value instead. Generic functions infer their type arguments from the arguments and children. A tag can also supply a type explicitly.
Pure functions and capabilities
Functions are pure by default: they read their arguments, immutable outer
let values, and pure helpers. Local scratch mutation is allowed. Mutable
parameters, live signals, external reads, and observable effects require
explicit capabilities:
let offset = 2
fn double(value: Number): Number { return value * 2 + offset }
mut count = 0
fn<ref> current_count(): Number { return count }
fn<mut, ref> increment(): Unit { count = count + 1 }
fn introduction(): Animation { return wait(2s) }
mutpermits mutable parameters and observable writes.sigpermits live signal parameters and returns.refpermits reading outer mutable/signal state or external resources.
Capabilities belong to function types (e.g., fn (value: Number): Number or
fn<ref> (): Number). A caller must permit the capabilities its callees
require. Regular boolean assert(condition, message=...) and read-only data
queries are pure.
Random values
Random(seed=42) gives you a reproducible source of random values. The
seed defaults to 0. Seeds and sample indices are nonnegative 64-bit
integers. Each method uses the index you give it, so you can sample in any
order and still get the same results.
number and integer include min and exclude max. With no bounds,
number samples from 0 up to 1. Pass two bounds with the same unit to
sample a percentage, duration, angle, or other unit directly. integer
requires both bounds. chance accepts a probability from 0 to 1, and
choose returns one element from a nonempty list or array.
Function documentation
Put consecutive # or ## comment lines immediately above a function
declaration to document it. The language server shows the Markdown summary
in hover, completion, and signature help. Use @param for an individual
parameter, @returns for the result, and @example for example code.
## Offset a position by the scene margin.
## @param position - The original horizontal position.
## @returns The position with the margin added.
fn inset(position: Length): Length { return position + 8pt }
Write separate comments above overload clauses to describe their behavior. The language server also displays documentation for standard library functions, types, constants, and methods.
Anonymous functions
Anonymous functions use the same typed parameter and return syntax and can capture lexical bindings:
Partial application
Supply one or more named arguments to a single-clause function and leave a required argument open to get a function for the remaining parameters. Ebi checks the supplied arguments against their declared types. If all required arguments are present, Ebi calls the function and uses defaults for any omitted optional arguments.
A partial call samples ordinary arguments when it binds them. A sig
parameter keeps its input live. You can pass the resulting function to
another function, return it, or put it in an immutable list or record.
Signal parameters and returns
See Signals for live parameters and return values.
Guarded function clauses
A function can have multiple disjoint clauses selected by literal strings or numeric refinements:
Int is an integer refinement of Number. Comparisons use matching units
(e.g., Duration <= 1s). Clause domains must be provably disjoint—overlap is
an error rather than source-order priority.
List lengths in types
List<T, N> describes exactly N elements. Omitting N or writing
_ leaves the length unspecified:
let values = [1, 2, 3] # List<Number, 3>
let triple: List<Number, 3> = values
let arbitrary: List<Number> = values
let also_arbitrary: List<Number, _> = values
type Pair<T> = List<T, 2>
The checker enforces known lengths in assignments, calls, returns, and typed
reads. map, scan, sort, and
reverse preserve length; zip takes the shorter length; concat adds
lengths.
Typed persistent-list operations
List methods return new immutable lists and accept named, generic, guarded, or anonymous callbacks:
| Method | Behavior |
|---|---|
map(callback) / flat_map(callback) | Transform each item; flat-map concatenates returned lists. |
filter(callback) | Keep items whose predicate returns true. |
reduce(callback) | Combine from the first item; an empty list is an error. |
fold(initial, callback) | Combine from an explicit initial value; empty input returns it. |
scan(initial, callback) | Return the accumulator after each item; output length equals input length. |
any / all / find / position | Short-circuit a predicate. find and position return Option. |
enumerate() / zip(other) | Return records {index, value} or {left, right}; zip stops at the shorter input. |
take(count) / drop(count) / slice(start=..., end=..., step=...) | Select sublists. Slicing uses the same bounds as items[start:end:step]. |
reverse() | Return reversed values without mutating the input. |
sort(key=..., reverse=false) | Stable sort; optional scalar keys are evaluated once per item. |
unique(key=...) | Keep each scalar key's first occurrence in input order. |
bisect_left(value, lo=..., hi=...) | Insertion position before equal keys in ascending sorted input. |
bisect_right(value, lo=..., hi=...) | Insertion position after equal keys in ascending sorted input. |