LEARN VOID / 02

Variables & constants

Give values a name.

Mutable variables, readonly bindings and type inference.

variables.voidDownload source ↓
const step: i32 = 2

func entry(value: i32) -> i32:
    var total = value
    total += step
    const snapshot = total
    return snapshot
Input 10Expected result 12

Change a variable

var introduces a mutable binding. In var total = value, the compiler infers i32 from the parameter. Later, total += step changes the existing variable; it does not declare another one.

Keep a binding readonly

const prevents assignment through that binding. The module-level step is a compile-time constant. The local snapshot is a readonly binding created while the function runs.

For managed objects, a readonly view does not mean that every other alias is frozen. Another mutable alias can still change the same object.

Choose when to show the type

Write a type after a colon when it helps communicate intent, as in const step: i32 = 2. Inference keeps straightforward local declarations short.