A short tour of Elder

Named types, functors, operators, optional values, and deferred arguments.

Named types and bindings

Declare a named, closed type when you know the fields. Give each field a type and use the name at bindings and parameters. Use list(T) for a sequence and map(K, V) for a dictionary with a changing set of keys.

Person::(name: string, role: string, years: int)
person: Person := Person(name = "Ada", role = "engineer", years = 12)

print person/name        // → "Ada"

// A typed local can be updated with =.
years: int := person/years
years = years + 1

nums: list(int) := [1, 2, 3, 4]
print nums/length        // → 4
print nums[0]            // → 1

A missing required field, an extra field, or an invalid value fails at the typed bind. := declares a binding. = names a field inside a literal and updates an existing binding in an execution block.

Functors: many inputs, many outputs

Definitions use name::(params) { body }. A functor is a stateful unit: params are its inputs, and every member it binds is an output you read by name. return is the opt-in for single-value calls, not the only way to get data out.

// Default arguments use = in the parameter list
greet::(who: string, loud: bool = false)
{
    if (loud) { return "HEY " + who }
    return "hi " + who
}

print greet("ada")              // → "hi ada"
print greet("ada", loud = true) // → "HEY ada"

// Multi-output: no return — the call yields the instance,
// and every bound member is a named result.
stats::(xs: list(number))
{
    total: number := 0
    count: int := xs/length
    for (xs) [x] { total = total + x }
    mean := if (count > 0) { total / count } else { null }
}

s := stats([2, 4, 6])
print s/total    // → 12
print s/mean     // → 4

Operators are functors — and whitespace is meaningful

Symbolic operators are ordinary functor names with a precedence table, not grammar. The headline rule is /: tight (a/b) is path/member access, spaced (a / b) is division. One character, two jobs, decided by whitespace.

// Arithmetic
print 7 + 3            // → 10
print 7 * 3            // → 21
print 10 / 4           // → 2.5   (spaced / is division)
print 7 % 3            // → 1

// Tight / is access; the two compose the way they read
Chunk::(size: int)
chunk: Chunk := Chunk(size = 2)
total := 10
print total / chunk/size   // → 5

// Comparison and logic — and/or short-circuit; | and & are eager
print 1 < 2 and 2 < 3  // → true
print (not false)      // → true

// A type can define its own operators (receiver-local override)
vec::(x: number, y: number)
{
    + ::(other) { return vec(../x + other/x, ../y + other/y) }
}
c := vec(1, 2) + vec(3, 4)
print c/x              // → 4
print 1 + 2            // → 3 (plain numbers skip the override path)

Overrides follow one lookup order for nearly every binary operator: a current-scope op::(lhs, rhs) functor, then a receiver-local op::(rhs) member, then the native default — so 1 + 2 pays no dispatch cost. Parentheses always win when precedence is in doubt.

Null, optional chaining, and ??

Missing values are null (the older none spelling is deprecated). null absorbs member access, so a whole path degrades gracefully instead of erroring mid-chain — and ?? coalesces exactly null, keeping legitimate falsy values.

ServerConfig::(port: int)
AppConfig::(server: optional(ServerConfig) = null)
cfg: AppConfig := AppConfig()
print cfg/server/port ?? 8080   // → 8080 (null absorbs the chain)

print false ?? 5                // → false (kept — `or` would lose it)
print 0 ?? 5                    // → 0
print null ?? 5                 // → 5

// Reading an undeclared member is governed by the functor's openness:
strict_cfg::(host: string) { }
loose_cfg: open : (host: string) { }

// strict_cfg("a")/port  → throws "Unknown name: port" (catchable)
print loose_cfg("a")/port ?? 80  // → 80 (open functor: missing reads null)

Deferred parameters: call-by-need

A parameter marked defer captures its argument unevaluated; it runs the first time the callee reads it, memoized after that. Never read means never run. This is how short-circuiting operators like ?? are ordinary library code instead of special grammar.

side := 0
bump::() { side = side + 1; return "b" }

pick::(cond: bool, alt: defer)
{
    if (cond) { return "kept" }   // alt never read — bump() never runs
    return alt                    // read here: force once, memoize
}

print pick(true,  bump())   // → "kept"
print side                  // → 0
print pick(false, bump())   // → "b"
print side                  // → 1

Control flow

if, while, for, try/catch — statements, with one twist: control-flow keywords are functor-shaped, so they participate in the same override machinery as everything else.

i := 0
while (i < 3)
{
    print i
    i ++
}

// Iterate the values of a typed list.
values: list(int) := [10, 20, 30]
for (values) [x]
{
    print x
}

// Iterate the keys of a typed dictionary.
m: map(string, int) := [a = 1, b = 2]
for (m) [k]
{
    print "{k} = {m[k]}"
}

// try/catch for genuinely exceptional faults
try
{
    x := 1 / 0
}
catch (err)
{
    print "caught: {err/message ?? err}"
}

Errors are values

The standard library makes a deliberate distinction. try/catch exists for genuinely exceptional faults (divide by zero, unknown name, contract violations). io/* calls return a flat record with an ok field instead — failure is normal control flow, not an exception.

// A failed request is a value you branch on — not a thrown exception.
resp := io/http/get(url = "https://api.example/v1/widgets", timeout_ms = 5000)
if (resp/ok and resp/code == 200)
{
    print resp/body
}
else
{
    print "request failed (code {resp/code})"
}

// Files carry the same envelope on success:
r := io/file/read(path = "config.json", encoding = "utf8")
if (r/ok) { print r/data }

The convention scales: io/file/*, io/http/*, io/process/* all return [ok = bool, …] with operation-specific fields on success and typed error detail when ok is false. One deliberate carve-out: reading a path that does not exist raises — probe io/file/exists first when absence is an expected case.

Modules and packages

Modules are private by default; export is the contract boundary. import resolves a logical package by name — through the local package store and the Constellatus registry — while include inlines a local file at parse time. Use import for dependencies, include for project-internal file splits.

// Namespace import — only the package's exports are visible
oidc := import("platform/provider-oidc")

// Selective destructuring over the same namespace
[verify_id_token, descriptor] := import("platform/provider-oidc")

// include inlines a local file at parse time (project-internal splits):
//   include "./helpers.ldr"

// In your own module: private by default, export explicitly
answer::() { return 42 }
export answer

Strings

Four flavors; pick by what needs to be literal. Interpolation lives in double quotes; single quotes are raw.

Comments

Line comments are // or #. Block comments /* … */ nest. /// doc comments feed hover and signature help in the LSP.

Where to next

Continue to Contracts for named types and typed boundaries, Concurrency for structured parallelism, IO & storage for persistence, or Tooling for the toolchain. The examples page has runnable programs.