渲染zh-Hant

變值

Translation status: 繁體中文 reader-locale proof. Term names and code fences follow the zh-Hant pack; supporting prose may still be English.

Declares a mutable binding.

Aliases: let, mutable

Syntax: 變值 <type|_> <pattern> [← <expression>]

Category#

binding

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