Syntax Reference
Everything you need to read and write Loon.
Delimiters
[...]
Function call or special form. The first element is always the operator.
{...}
Map literal. Alternating key-value pairs: {:name "Ada" :age 30}
#[...]
Vector literal: #[1 2 3]
#{...}
Set literal: #{"a" "b" "c"}
(...)
Reserved. Not used in Loon syntax.
Literals
"hello"
String. Double-quoted, supports escape sequences (\n, \t, \", \\).
42
Integer. 64-bit signed.
3.14
Float. 64-bit double precision.
true / false
Boolean values.
:name
Keyword. A lightweight identifier, often used as map keys.
None
Absence of a value. Part of the Option ADT.
Empty
Empty collection sentinel.
Special Forms
fn
Define a named or anonymous function: [fn name [params] body] or [fn [params] body]
let
Bind a value to a name: [let x 42]
if
Conditional: [if cond then else]. Branches do NOT have implicit do.
do
Evaluate multiple expressions, return the last: [do expr1 expr2]
match
Pattern matching with positional pairs: [match val pat1 body1 pat2 body2]. Expression guards supported.
type
Define an algebraic data type.
effect
Declare an effect with operations.
handle
Handle effects with an effect handler.
macro
Define a macro that operates on syntax.
macro+
Define a type-aware macro (expanded after type checking).
test
Define a test: [test "name" [params] body]
use
Import a module or members from a module.
pub
Export a binding from a module.
sig
Type signature annotation.
try
Attempt an operation that may fail.
pipe
Thread a value through a series of transformations: [pipe x f g h]
quote
Prevent evaluation of an expression.
unquote
Evaluate inside a quoted expression.
derive
Derive trait implementations for a type.
Comments
; this is a comment
[let x 42] ; inline commentString Interpolation
[let name "world"]
"hello, {name}!" ; "hello, world!"
"2 + 2 = {[+ 2 2]}" ; "2 + 2 = 4"Quasiquoting
`expr
Quasiquote. Like quote but allows unquoting inside.
~expr
Unquote. Evaluate expr inside a quasiquote.
~@expr
Splice-unquote. Evaluate and splice a list into the surrounding form.
Operators
+ - * / %
Arithmetic. Work on integers and floats.
= !=
Equality and inequality. Work on all types.
< > <= >=
Ordering comparisons. Work on numbers and strings.
not
Logical negation.
and / or
Logical conjunction and disjunction. These are eager, not short-circuiting.
and/or evaluate both arguments eagerly. Use nested if for short-circuit logic.