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