Syntax
Comments
Section titled “Comments”// line comments start with two slashesIdentifiers
Section titled “Identifiers”Identifiers and record properties use kebab-case:
fn get-text(item-count: Int): String => ...A hyphen continues a name only when the part after it isn’t just digits: pos-2d-to-3d is one name,
but x-1 is x minus 1, and the compiler asks for spaces (x - 1).
Type names (Message, Seq, Optional) are capitalized. None is always spelled with a
capital N.
Names that come from C are used exactly as C spells them (gl_clear, SDL_Init). Kebab-case is
only a Kura style convention.
Bindings
Section titled “Bindings”let binds a name to a value:
let width = 10pxlet accent: Color = blueValues are immutable. You can rebind a name, but you can’t mutate a value:
let x = { name: "Person 1" }x = { name: "Person 2" } // valid: a new value for xx.name = "Person 2" // not valid: values can't be mutatedFunctions
Section titled “Functions”A function is introduced by fn. Parentheses are always required, even with no parameters:
fn add(x: Int, y: Int): Int => x + y
fn answer(): Int => 42The body is a single expression after =>. Use a block to sequence let bindings. The last
expression is the block’s value:
fn total(): Int => { let base = 10 let padding = 4 base + padding * 2}Functions are first-class. See Primitives.
Lambdas
Section titled “Lambdas”fn add-one(x: Int): Int => apply((a, b) => a + b, x, 1)Braces: record or block?
Section titled “Braces: record or block?”{} is a record when it appears as a value, and a block everywhere else
(function bodies, if branches, element children).
fn pos(): Position => { x: 1, y: 2 } // recordfn sum(): Int => { let a = 1 a + 2 } // block{ x } is a block that returns x. With a comma, { x, } is a record with one pun: it means
{ x: x }. Element arguments pun the same way: #button(width,) is #button(width: width). Positional
arguments come last.
Records
Section titled “Records”Records are covered in Primitives. A few composition forms:
let p2 = { ...p1, y: 20 } // spread: later fields winlet p3 = p1 + { z: 30 } // combine two recordsA record can be copied with some fields changed. Only the listed fields change, and a path reaches into nested records:
let p4 = { p1 | x: 5 } // x is 5let p5 = { p1 | x += 1, y -= 2 } // x: p1.x + 1, y: p1.y - 2let m2 = { model | player.hp -= 1 } // a nested fieldSpread (...) is written inside a record literal. + between records produces a new record
with the fields of both.
Sequences
Section titled “Sequences”let items = [ 1, 2, 3 ]let all = items + [ 4, 5 ] // a new Seq: [ 1, 2, 3, 4, 5 ]let first = items[0]let init = items[0..-1] // a slice: [ 1, 2 ]Ranges
Section titled “Ranges”a..b leaves out b, a..=b includes it, and either end can be left open: 3.., ..5.
They are used for slices and in patterns (0..10 => ...).
Strings
Section titled “Strings”A { in a string interpolates one expression; \{ and \} are literal braces. The escapes are \n, \t,
\", \\, \{ and \}. A string is on one line: write \n for a line break.
#text("{pos.x}, {pos.y}")#text("{count} items, {label}")The value is put in the string as it is written in a program: a string as it is, 7 as 7, 1.5 as 1.5, a
Float with no fraction as 2.0, true as true, 10px as 10px, and a variant by its name. An interpolation
can hold any expression, including a string with interpolations of its own. Format specifiers, like {x:.2},
are reserved.
Optional values
Section titled “Optional values”a ?? b is b when a is None. a?.b is None when a is, and otherwise a.b; the same goes for
calls and indexes, f?.(x) and xs?.[0].
let x = entity?.pos?.x ?? 0.0Casts and assertions
Section titled “Casts and assertions”A type’s name converts: Float(x). A conversion that loses information traps.
static-assert(cond, "message") checks a condition while compiling.
value is pattern tests the shape of a value with the same patterns as match:
x is Float, m is Click(_). In the condition of an if, put a record pattern in parentheses:
if (p is Point { x, y }) { ... }.
Operators
Section titled “Operators”| Operator | Meaning |
|---|---|
+ - * / % |
Arithmetic |
?? |
Default for None |
.. ..= |
Ranges |
>> << <| |
Composition and application |
== != < <= > >= |
Comparison |
&& || ! |
Boolean logic |
|> |
Pipe |
Literals
Section titled “Literals”| Literal | Type |
|---|---|
10 |
Int |
10.5 |
Float |
true, false |
Bool |
"text" |
String |
10px |
Px |
50% |
Pct |
1fr |
Fr |
blue, red, … |
Color |
None |
None |
The named colors are black, white, red, green, blue, yellow, cyan, magenta,
gray, orange, purple and transparent.