Guide 02

Language tour

Lume favors explicit data and control flow without requiring ceremony around ordinary application code. This tour explains the stable mental model; the full syntax reference remains authoritative.

Bindings and mutation

A bare assignment introduces an immutable binding. Add a type when it improves the contract or supplies context for inference. Mutable bindings use var, while reassignment uses :=.

name = "Ada"
count Int = 1
var retries = 3
retries := retries - 1

Local bindings cannot silently shadow parameters, fields, or another live local. Field access can be qualified with this when a parameter has the same name.

Classes, shapes, unions, and objects

A class is nominal: construction and class-to-class assignment depend on its declared identity. A shape is structural data with public, read-only field bindings. Shape immutability is shallow: referenced values retain their own mutability rules. A declared union closes over class, shape, and object alternatives, while a standalone named object declares one shared object value.

shape Location {
    city Str
    country Str
}

class User {
    name Str
    location Location

    new(name Str, location Location) = {
        this.name = name
        this.location = location
    }
}

type Access =
    object Admin {}
    | class Member { organization Str }

object Defaults {
    country Str = "US"
}

Interfaces describe behavior. Classes, shapes, annotations, and named objects can explicitly implement interfaces. Shared union behavior belongs in an ext block on the union.

Construction

Class constructors are declared with new(...). Braces supply construction fields by name, while parentheses supply explicitly positional constructor inputs in declaration order.

ada = User {
    name: "Ada"
    location: Location("London", "UK")
}

Anonymous shapes use the same named field form without a type name:

summary = {
    name: ada.name
    active: true
}

Short guards and loops

Use then for a single-statement conditional body and do for a single-statement loop body. Braced bodies remain valid. Newlines are layout, not indentation-based scope; multiple statements require a block.

if invalid then return
if count == 0 then println("empty")
else if count == 1 then println("one")
else println("many")

label = if active then "enabled" else "disabled"
while pending do processNext()
for item <- items do process(item)
for { item <- items } do process(item)

Pattern matching and destructuring

let supports irrefutable destructuring directly. Refutable bindings require an else path. if let branches on a pattern, and match handles alternatives exhaustively.

let { name, location } = ada

let Some { value as first } = users.at(0) else return

label = match access {
    case Admin => "administrator"
    case Member { organization } => organization
}

Tuple, vector, shape, class, and union-alternative patterns are name-aware where the source data is named. Vector patterns may capture a remainder with spread syntax.

Option, Result, Either, and try

Lume represents optional values and recoverable failure explicitly. try unwraps the success side and propagates the container's failure. Use mapError or mapLeft before try when the enclosing function uses a different error type.

fn load(id Int) Result[User, AppError] = {
    row = try Db.queryRow("select ...", id)
        .mapError(error => AppError.Db(error))

    Ok(decodeUser(row))
}

Use explicit map and flatMap calls when transforming values inside Option, Result, or Either.

Vectors and maps

Collection types and literals use parallel bracket syntax. An empty [] uses its expected vector or map type.

names [Str] = ["Ada", "Grace"]
scores [Str: Int] = ["Ada": 10, "Grace": 12]

emptyNames [Str] = []
emptyScores [Str: Int] = []

Higher-order methods accept explicit lambdas or compatible function and bound-method references. A lambda uses => and may use a block body.

lengths = names.map(name => name.size())
labels = names.map(name => {
    upper = name.upper()
    "$upper!"
})

Deferred work uses ordinary zero-argument function parameters. { => expression } is a short zero-argument lambda; its body runs only when the function is invoked.

fn repeat(work fn() Int) Int = work() + work()

fallback fn() Str = { => "unavailable" }
result = repeat { => calculate() }
recovered = maybe.orElse { => loadBackup() }

Java source generation and interoperability

The frontend completes parsing, resolution, and type checking before Java source is generated. Java-specific class loading and descriptors live at the backend boundary, allowing the core compiler model to remain Lume-oriented.

cargo run --manifest-path rust/Cargo.toml -p lume -- \
    gen app/main.lum --out build/generated/lume

Generation produces readable, source-shaped Java. Unsupported method bodies are reported as compiler diagnostics rather than emitted as low-level control-flow machines.

Lume libraries can wrap Java dependencies behind Lume interfaces. The repository includes database, JSON, HTTP, Gradle, and Java compatibility examples.

This page is an introduction, not a complete grammar. Continue with the current syntax reference for visibility, constructors, annotations, generics, comprehensions, operators, and exact diagnostics.