Syntax at a Glance
Every piece of syntax in this article has a full explanation in its corresponding chapter; this page is only a quick reference, so follow through to the chapters for the complete content.
// ── Bindings and basic values ───────────────────────────────
val a = 1; // immutable
var b = 2; // mutable
b = b + 1;
const K = 42; // compile-time constant
val n: int = 0xff; // eight integer widths: int8..int64 / uint family; 0x / 0b / 0o prefixes
val f: float = 1.5e3; // binary floating point: float / f64 / f16
val ok: bool = true;
val c: char = 'é'; // single quotes, one grapheme cluster
val s = "text \n escape"; // double-quoted string with escapes
val raw = r"C:\path {as-is}"; // raw string: no escapes, interpolation optional
val wait = 1.5s + 500ms; // time values: us / ms / s / min / hr
val v = vec2(1.0, 2.0); // vectors: vec2..vec4 / vec2i..vec4i / color
val col = #ff8000ff; // color literal
val x = v.x; // swizzle: x/y or r/g/b pick components directly
print($"interpolated {s} and {n * 2}, aligned [{f,10}]");
// ── Containers ──────────────────────────────────────────────
val xs: list<int> = [1, 2, 3]; // list
val uniq: set<int> = [1, 2, 2]; // deduplicating set
val arr = [4, 5, 6]; // array
val buf = new int[3]; // allocated by length
val filled = new int[5](i => i * i); // factory form: invoked per slot
val m = new map<string, int>(); // map
m["gold"] = 1;
xs.Add(4); // append at the end
xs[0] = 9; // write through the indexer
print(xs.Count, m["gold"], arr.Length);
val evens = xs.Where(x => x % 2 == 0); // higher-order methods: Where / Map / Filter / Reduce
// ── Control flow ────────────────────────────────────────────
if n > 0
{
print("positive");
}
elif n < 0
{
print("negative");
}
else
{
print("zero");
}
val sign = if n > 0 { "positive" } else { "non-positive" }; // if expression
if val first = xs.Get(0) // conditional binding
{
print(first);
}
match n
{
0 => print("zero"),
x when x < 0 => print("negative"), // guard
_ => print("other"),
}
for x in xs // for-in
{
print(x);
}
for i in 0..10 { } // half-open range; closed range is 1..=10
for i in 1..=6 when i % 2 == 0 { } // loop guard
while b < 100 { b = b * 2; }
while val w = maybe // conditional-binding loop: null exits
{
b = b + w;
}
repeat 3 { print("three times"); }
for i in 1..=3 label outer { break outer; } // labeled jump
defer { print("runs in reverse order at scope exit"); } // cleanup hook
// ── Functions ───────────────────────────────────────────────
func Add(a: int, b: int) -> int
{
return a + b;
}
func Greet(name: string, punct: string = "!") -> string // default parameters
{
return $"Hello, {name}{punct}";
}
Greet("world", punct: "."); // named arguments
func Swap(ref a: int, ref b: int) { } // ref writes back; out is write-only
func Total(params nums: int[]) -> int { } // variadic: Total(1, 2, ...xs)
func Show(v: int) -> string => $"int {v}"; // expression body
func Show(v: string) -> string => $"string {v}";// overloads: resolved by argument types
func Max<T>(a: T, b: T) where T: Ordered -> T // generics and constraints
{
return a < b ? b : a; // ternary
}
// ── lambda and pipelines ────────────────────────────────────
val square = (x: int) => x * x; // lambda
val added = (a: int, b: int) fail Bad => a + b; // failable lambda
xs.Map(x => x * 2);
val total = xs
|> Where(x => x % 2 == 0) // pipeline: the left value inserts as the first argument
|> Map(square)
|> Reduce((acc, x) => acc + x, 0);
val safe = maybe ?|> Wrap; // null-safe pipeline: short-circuits on null
val tried = input |>? Load; // fallible pipeline
val must = input |>! Load; // propagating pipeline
// ── Custom types ────────────────────────────────────────────
struct Pt
{
public val x: int;
public val y: int;
init(x: int, y: int)
{
self.x = x;
self.y = y;
}
}
class Animal
{
public virtual func Speak() -> string => "...";
}
class Dog : Animal // single inheritance; : base(n) chains constructors
{
public override func Speak() -> string => "woof";
}
data Item { label: "text" } // data: the type is the value
data Sword
{
...Item, // spread merge
name: "iron sword",
}
enum Color { Red, Green, Blue }
enum Shape { Circle(radius: float), Rect(w: float, h: float), Point }
flags Perm { Read, Write, Execute = 16 } // flags
val p = Perm.Read | Perm.Write;
protocol Greeter { func Hello() -> string; }
class Robot impl Greeter // protocol implementation
{
public func Hello() -> string => "beep";
}
mixin Noisy { public func Noise() -> string => "boom"; }
class Machine with Noisy { } // mixin: members cloned at compile time
extension int // extension: inject members into an existing type
{
public func Squared() -> int => self * self;
}
class Meter
{
public var value: int = 0;
public computed prop Double: int => self.value * 2; // derived read
public prop Level: int // explicit accessors
{
get => self.value / 10;
set { self.value = value * 10; }
}
}
val frozenList = freeze([1, 2, 3]); // deep-freeze: fully read-only
// ── Failure and consumption ─────────────────────────────────
error NotFound(key: string); // error declaration
func Load(key: string) fail NotFound -> int // fail clause
{
if key == ""
{
fail new NotFound(key); // raise an error value
}
return key.Length;
}
val soft = try? Load(""); // failure yields null
val hard = try! Load("x"); // assert success; failure crashes
val r = capture Load(""); // collect into a result value
recover r
{
Success(v) => print(v),
Failure(e) => print(e.key), // read the error payload directly
}
crash new NotFound("dead end"); // crash with an error
// ── Async ───────────────────────────────────────────────────
async func Fetch() -> string
{
await 1s;
return "data";
}
val job = spawn // runs concurrently
{
await 0.5s;
};
cancellable async func Work() -> int // cancellable: negotiates via cancel.requested
{
if cancel.requested
{
return -1;
}
return 42;
}
// ── Events ──────────────────────────────────────────────────
event Ticked(n: int); // event declaration
func OnTick(n: int) { print(n); }
Ticked ~> OnTick; // subscribe
Ticked !~> OnTick; // unsubscribe
emit Ticked(1); // emit
// ── Attributes and reflection ───────────────────────────────
attribute Doc(text: string) targets type, method;
@Doc("sample type") // applied
class Widget { }
val t = typeof(Widget);
print(t.Attrs()[0].Args()["text"]); // read attributes via reflection
print(Reflect.TypeOf(1.5).Name);
// ── Organization and scope ──────────────────────────────────
module Shop; // module declaration at file top
import Math.*; // import
using val res = MakeResource(); // Dispose runs automatically at block exitLast updated on October 11, 2026
