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 0Explicit type annotations
func main() -> i32: let count: i32 = 10 let ratio: f64 = 1.5 let label: str = "ok" let done: bool = false return 0Supported primitive types
| Type | Description | Example |
|---|---|---|
i32 | 32-bit signed integer | let x: i32 = 42 |
i64 | 64-bit signed integer | let x: i64 = 1000000000 |
f64 | 64-bit floating point | let x: f64 = 3.14 |
bool | Boolean | let b: bool = true |
str | String handle | let 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 - 2Scope
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 resultTop-level constants
Use const for module-level immutable values. const requires an explicit type annotation:
const MAX: i32 = 100const SCALE: f64 = 0.5Arrays
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 totalArrays cannot be created with literal syntax. They come from stdlib functions such as io.read_ints and string.split.