Skip to content

Variables & let

Variables & let

Declaring variables

Use let to create a local binding. The type can be annotated explicitly or inferred from the initializer:

func main() -> i32:
let x = 42
let ratio = 3.5
let name = "thagore"
let flag = true
return 0

Explicit type annotations

func main() -> i32:
let count: i32 = 10
let ratio: f64 = 1.5
let label: str = "ok"
let done: bool = false
return 0

Supported primitive types

TypeDescriptionExample
i3232-bit signed integerlet x: i32 = 42
i6464-bit signed integerlet x: i64 = 1000000000
f6464-bit floating pointlet x: f64 = 3.14
boolBooleanlet b: bool = true
strString handlelet s: str = "hello"

The float type is f64. There is no f32 user-facing type in the current compiler.

Reassignment

let bindings are mutable by default — reassign with =:

func main() -> i32:
let x: i32 = 1
x = x + 1
return x - 2

Scope

Variables are scoped to their enclosing block:

func classify(value: i32) -> i32:
let result: i32 = 0
if (value > 0):
let adjusted: i32 = value + 1
result = adjusted
return result

Top-level constants

Use const for module-level immutable values. const requires an explicit type annotation:

const MAX: i32 = 100
const SCALE: f64 = 0.5

Arrays

Arrays are runtime-backed. The type is Array[T]:

func sum(items: Array[i32]) -> i32:
let total: i32 = 0
for item in items:
total = total + item
return total

Arrays cannot be created with literal syntax. They come from stdlib functions such as io.read_ints and string.split.