Variables & Mutability — Mapanare
Bindings, type inference, and controlled mutation in the Mapanare programming language.
Let Bindings
Variables are declared with let and are immutable by default. The type is inferred from the right-hand side when not annotated.
let x = 42 // inferred as Int
let name = "Mapanare" // inferred as String
let pi: Float = 3.14159 // explicitly annotated
Mutability
Add mut to allow reassignment. Immutable is the default to encourage safer, more predictable code.
let mut count = 0
count = count + 1
count += 10
let frozen = 100
// frozen = 200 // compile error: cannot assign to immutable variable
Type Inference
The compiler infers types from literals, function return types, and expressions. You only need explicit annotations on function parameters and return types.
let a = 42 // Int
let b = 3.14 // Float
let c = true // Bool
let d = 'x' // Char
let e = "hello" // String
let f = [1, 2, 3] // List<Int>
let g: Option<Int> = none // annotation needed (none is ambiguous)
Compound Assignment
Mutable variables support: +=, -=, *=, /=
Numeric Literals
let decimal = 1_000_000
let hex = 0xFF
let binary = 0b1010_0101
let octal = 0o777
let sci = 1.5e10