渲染zh-Hant

varia

Translation status: 繁體中文 reader-locale proof. Code fences render through the zh-Hant pipeline; prose is canonical Latin.

Declares a mutable binding.

Aliases: let, mutable

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

Category#

binding

Examples#

radix/corpus/varia/varia.fab (canonical · keyword)#

Declares a mutable binding.

# =============================================================================
# varia — Declares a mutable binding.
# =============================================================================
#
# What this teaches:
#   • Mutable bindings — `varia` for values that can be reassigned after declaration
#   • Immutable bindings — `fixum` and `sit` for values that cannot be reassigned
#
# Common mistakes:
#   • declaring varia when the binding is never reassigned — use fixum instead (WARN013)
#
# See also: fixum, ←, ⊕
# =============================================================================




# Mutable and immutable variable declarations
#
# varia <nomen> ← <expr>   -- mutable binding (may reassign)
# fixum <nomen> ← <expr>   -- immutable binding (see fixum/fixum.fab)
#
# GRAMMAR:
#   bindingStmt :← ('varia' | 'fixum') type? ident '←' expr
#
# EXPECTED OUTPUT:
#   0, 1, 11, "Salve, Mundus!", 30, "Vale"

main {
    # --- Mutable bindings with varia ---

    var _ computus  0
    print computus

    computus  1
    print computus

    computus  computus + 10
    print computus

    # --- Immutable bindings: fixum _ and sit ---

    const _ salutatio  "Salve, Mundus!"
    print salutatio

    # sit compresses repeated fixum _ when chaining inferred locals
    let x  10
    let y  20
    let summa  x + y
    print summa

    # --- Reassign only varia bindings ---

    var _ nuntius  "Salve"
    nuntius  "Vale"
    print nuntius
}

Expected output:

0
1
11
Salve, Mundus!
30
Vale