Variables and bindings

Three binding forms: immutable let, mutable var, and constant const. All support type annotations and destructuring.

let, var, const

scratch.xs

Reassigning a let binding is a runtime error. const is identical to let at runtime; the distinction is for the reader.

scratch.xs

Compound assignment (+=, -=, *=, etc.) requires var.

Type annotations

Annotations are optional. Add them where you want the type checker to enforce correctness.

scratch.xs

Without annotations, code runs fine and the checker stays silent. With annotations, the checker catches mismatches before execution:

let x: int = "oops"
-- error[T0001]: type mismatch: expected 'int', got 'str'

Destructuring

Unpack arrays, tuples, and structs in a single binding:

scratch.xs
scratch.xs

Deleting variables

del removes a name from the current scope. Accessing it afterward throws a runtime error.

scratch.xs