Syntax & Control Flow
Minimal end-delimited blocks, 23 reserved keywords, mutable value semantics, second-class do blocks, use flattening, and native structured loops.
Lexical structure & capitalization
Exp has exactly 23 reserved keywords (fn do end if then else match with
type effect handler handle use for in while loop break continue return defer import export)
plus 5 reserved literal/operator words (true false and or not). Keywords are legal
in record field positions (x.end, { type: 1 }).
- Capitalization separates namespaces: leading uppercase
names belong to the type namespace (types, effects, constructors, handlers, abilities);
leading lowercase names belong to the value namespace (functions, locals,
modules, fields). Patterns therefore parse cleanly without symbol-table lookup:
Some(x)is always a constructor pattern bindingx. - Comments:
--starts a line comment;---starts a doc comment attached to the following declaration (surfaced directly in LSP hover and interactive docs). - Literals & format strings: integer literals support underscores and
hex/binary/octal forms (
1_000_000,0xff) and adoptIntorFloatfrom context. Double-quoted strings interpolate anyShowvalue via{expr}with compile-time verified format specs ({price:.2},{n:08x}). Multi-line raw strings use'''...'''with automatic dedent. - Proof attributes:
#tailproves every recursive call is a proper tail call (E0059);#inline_blocksproves every literal-block combinator call allocates zero closures (E0060);#extern(...)declares typed host interop boundaries.
Values, variables & mutable value semantics
Exp has no let, var, or const keywords. Values are
immutable, while local variables can be reassigned:
-
x = exprassigns if a localxis already in scope in the current function (or enclosing function inside a second-classdoblock); otherwise it declaresx. -
Local shadowing (
E0034) and unused locals (E0035) are compile errors. Discard intentionally with_ = expr. -
Top-level bindings are pure immutable constants (
E0036on reassignment). -
Field and index updates (
user.age = 37,scores[i] = 10) have pure value semantics — no aliasing is ever observable. When Core IR uniqueness analysis proves unique ownership, backends emit an in-place mutation with zero allocation.
type User
name: String
age: Int
end
fn birthday(u: User) -> User
-- Reassigning a field rebuilds the value with value semantics.
-- When uniquely owned, backends update in place with 0 allocation.
copy = u
copy.age = copy.age + 1
copy
end
fn main()
ada = User(name: "Ada", age: 36)
older = birthday(ada)
-- Original value is never aliased or mutated
print("{ada.name}: {ada.age} -> {older.age}")
endFunctions, lambdas & callback flattening (use)
Every fn declaration is rank-1 generalized in strongly connected component (SCC)
order while local bindings stay monomorphic. The final expression of a block is its implicit
return value.
| Form | Syntax | Notes |
|---|---|---|
| Single-expression lambda | x => x * 2, (a, b) => a + b | Concise expression-bodied closure or block |
| Zero-argument thunk | => compute() | Common in Async.all / Async.timeout |
| Field accessor | .name | Short for r => r.name |
Trailing do block | xs.each do |x| ... end | Passed as final argument; second-class when non-escaping |
| Callback flattening | use a, b = expr | Desugars to expr do |a, b| <rest> end |
| Handler flattening | use handle H1, h2 | Desugars to handle <rest> with H1 h2 end |
Inferred escape modes (blocks vs closures)
Every function-typed parameter is inferred automatically as either:
- Second-class (block): only called or forwarded to other second-class parameters. May assign enclosing locals, may capture scoped-control capabilities, and inlines with zero closure allocation.
- First-class (closure): stored, returned, or captured by an escaping value.
Cannot assign enclosing locals (
E0048— useRef<T>) and cannot capture scoped-control capabilities (E0047).
Match, loops & structured early exit
if/then/else/end and match/with/end are expressions. Pattern matching
supports constructors, literals, records ({ name, age: a }), tuples, list
cons ([head, ...tail]), or-patterns (A | B), guards, and
refinement (unwrapping a local scrutinee by the same name inside an arm).
for, while, loop, break,
continue, and return are first-class structured control flow that
lower directly to native target loops and returns — including native await inside
Async loops and LIFO try/finally cleanup on early exit.
fn sumPositive(xs: List<Int>) -> Int
total = 0
for x in xs do
if x < 0 then continue end
if x == 0 then break end
total = total + x
end
total
end
fn withDouble(n: Int, k)
k(n * 2)
end
fn compute() -> Int
-- 'use' passes the remainder of the block as the trailing do-block callback
use a = withDouble(10)
use b = withDouble(a + 1)
b
end
fn main()
print("sum={sumPositive([4, -2, 7, 0, 99])} compute={compute()}")
endOperator precedence & newline rule
Exp is free-form with one clean line-continuation rule: a newline ends an expression unless the
next line starts with a token that cannot begin an expression (a binary operator, .,
then, else, end, with, ),
], }). Bitwise operators bind tighter than comparisons so
x & mask == 0 parses as (x & mask) == 0.
module ::= item*
item ::= importDecl | attr* 'export'? (fnDecl | typeDecl | effectDecl | handlerDecl | binding) | expr
fnDecl ::= 'fn' fnName '(' params? ')' ('->' type ('!' row)?)? block 'end'
typeDecl ::= 'type' Upper typeParams? ( '=' 'distinct'? type | typeBody 'end' )
effectDecl ::= 'effect' Upper typeParams? opSig* 'end'
handlerDecl ::= 'handler' Upper ('(' params ')')? ':' type block? clause* 'end'
handleExpr ::= 'handle' (expr | NEWLINE block) 'with' (handlerRef | valueExpr | clause)* 'end'
matchExpr ::= 'match' expr 'with' (pattern ('if' expr)? 'then' block)* 'end'
forExpr ::= 'for' pattern 'in' expr 'do' block 'end'
useStmt ::= 'use' ( 'handle' handlerItem (','? handlerItem)* | (ident (',' ident)* '=')? expr )
lambda ::= ident '=>' expr | '(' params ')' '=>' expr | '=>' expr | '.' ident