varia
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: mut <type|_> <pattern> [← <expression>]
Category#
binding
Related#
Examples#
radix/corpus/reference/keyword/varia/varia.fab (canonical · keyword)#
Declares a mutable binding.
# =============================================================================
# mut — Declares a mutable binding.
# =============================================================================
#
# What this teaches:
# • Mutable bindings — `mut` for values that can be reassigned after declaration
# • Write-once bindings — `let` for values that cannot be reassigned
#
# Common mistakes:
# • declaring mut when the binding is never reassigned — use let instead (WARN013)
#
# See also: const, ←, ↑
# =============================================================================
# Mutable and immutable variable declarations
#
# mut <name> ← <expr> -- mutable binding (may reassign)
# let <name> ← <expr> -- write-once binding (see let/sit.fab)
#
# GRAMMAR:
# bindingStmt :← ('mut' | 'let') type? ident '←' expr
#
# EXPECTED OUTPUT:
# 0, 1, 11, "Salve, Mundus!", 30, "Vale"
main {
# --- Mutable bindings with mut ---
mut _ computus ← 0
print computus
computus ← 1
print computus
computus ← computus + 10
print computus
# --- Write-once bindings: let ---
let _ salutatio ← "Salve, Mundus!"
print salutatio
# let infers the type of each local
let _ x ← 10
let _ y ← 20
let _ sum ← x + y
print sum
# --- Reassign only mut bindings ---
mut _ nuntius ← "Salve"
nuntius ← "Vale"
print nuntius
}Expected output:
0
1
11
Salve, Mundus!
30
Vale
radix/corpus/reference/reject/varia/possibly-uninitialized-reject.fab (supporting · reject)#
Reading a deferred mut binding assigned on only one branch is refused.
# =============================================================================
# mut — A deferred mut binding must be assigned on every path before a read.
# =============================================================================
#
# What this teaches:
# • `mut int x` with no initializer defers the store to a later branch
# • definite assignment is per path, so a read outside that branch is refused
#
# Common mistake:
# • assuming `if true` is constant-folded away — both paths still count
#
# See also: mut, if, ←
# =============================================================================
# This exemplum intentionally fails to compile.
main {
mut int x
if true {
x ← 1
}
print x
}Expected: compilation rejects this example.