var
Translation status: English reader-locale proof. Term names and code fences follow the en pack; supporting prose may still be English.
Declares a mutable binding.
Aliases: let, mutable
Syntax: var <type|_> <pattern> [← <expression>]
Category#
binding
Related#
Examples#
radix/corpus/varia/varia.fab (canonical · keyword)#
Declares a mutable binding.
# =============================================================================
# var — Declares a mutable binding.
# =============================================================================
#
# What this teaches:
# • Mutable bindings — `var` for values that can be reassigned after declaration
# • Immutable bindings — `const` and `let` for values that cannot be reassigned
#
# Common mistakes:
# • declaring var when the binding is never reassigned — use const instead (WARN013)
#
# See also: const, ←, ↑
# =============================================================================
# Mutable and immutable variable declarations
#
# var <name> ← <expr> -- mutable binding (may reassign)
# const <name> ← <expr> -- immutable binding (see const/fixum.fab)
#
# GRAMMAR:
# bindingStmt :← ('var' | 'const') type? ident '←' expr
#
# EXPECTED OUTPUT:
# 0, 1, 11, "Salve, Mundus!", 30, "Vale"
main {
# --- Mutable bindings with var ---
var _ computus ← 0
print computus
computus ← 1
print computus
computus ← computus + 10
print computus
# --- Immutable bindings: const _ and let ---
const _ salutatio ← "Salve, Mundus!"
print salutatio
# let compresses repeated const _ when chaining inferred locals
let x ← 10
let y ← 20
let sum ← x + y
print sum
# --- Reassign only var bindings ---
var _ nuntius ← "Salve"
nuntius ← "Vale"
print nuntius
}Expected output:
0
1
11
Salve, Mundus!
30
Vale