Declarations & bindings
A declaration introduces a name the rest of the file can use. Four binding
words say how a name is bound: let is a fixed name, mut is re-pointable
and writable, ref is re-pointable and read-only, and const T X = e is a
compile-time fact. Every one writes its type slot, and _ asks for
inference. Functions, closures, and
classes are declarations too — they name a callable or a type, and the
fields and methods it holds.
The type always comes before the name: i32 count, never count: i32.
← stores a value at run time. = is for a field's shape inside a
literal, not for binding a local. Generic parameters (<T>), implements
bounds, and the modifiers on a function (async, throws, args) belong
here because they are part of how the name is declared.
A function and two bindings:
fn divide(i32 a, i32 b) → i32 ∪ none {
if b ≡ 0 then return null
return a / b
}
main {
let i32 seven ← 7
mut i32 n ← 3
n ← n + 1
print divide(seven, n)
}A class names its fields the same way. Methods are functions on the class;
self is the instance:
class Span {
let f64 low
let f64 high
fn contains(f64 x) → bool {
return self.low ≤ x and x ≤ self.high
}
}
main {
let Span bytes ← Span { low = 0.0, high = 255.0 }
print bytes.contains(128.0)
}Return to the grammar overview.
Terms#
These are the words you write in this part of the language. Each links to its page. The second column names the grammar rule the word belongs to.
| Term | Grammar rule |
|---|---|
embed | insere_expr |
const, const, mut | fixum_decl |
await_const, await_var | figendum_decl |
let, let | sit_decl |
ref | ref_decl |
let, mut | array_destruct |
let, mut | object_destruct |
fn | functio_decl |
kernel | kernel_decl |
implements | generic_bound |
rest, optional, as, coalesce | parameter |
args, errors, exit, throws, readonly, options | func_modifier |
async_generator, async, generator | callable_posture |
then | ergo_joint |
do | fac_block |
lambda | clausura_legacy_expr |
class, implements | genus_decl |
fn | nondum_method_decl |
let, optional, mut | genus_field_decl |
const | genus_const_decl |
let, optional, mut | field_decl |
fn | functio_method_decl |
Formal grammar#
The rules for this part of the language are the parser's own definition of it. They are written for models and tools, so this page does not repeat them; the full list is at every production.