Kết xuấtvi

biến

Translation status: Tiếng Việt reader-locale proof. Term names and code fences follow the vi pack; supporting prose may still be English.

Declares a mutable binding.

Aliases: let, mutable

Syntax: biến <type|_> <pattern> [← <expression>]

Category#

binding

Examples#

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

Declares a mutable binding.

# =============================================================================
# biến — Declares a mutable binding.
# =============================================================================
#
# What this teaches:
#   • Mutable bindings — `biến` for values that can be reassigned after declaration
#   • Immutable bindings — `hằng` and `đặt` for values that cannot be reassigned
#
# Common mistakes:
#   • declaring biến when the binding is never reassigned — use hằng instead (WARN013)
#
# See also: hằng, ←, ↑
# =============================================================================




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

main {
    # --- Mutable bindings with biến ---

    var _ computus ← 0
    print computus

    computus ← 1
    print computus

    computus ← computus + 10
    print computus

    # --- Immutable bindings: hằng _ and đặt ---

    const _ salutatio ← "Salve, Mundus!"
    print salutatio

    # đặt compresses repeated hằng _ when chaining inferred locals
    let x ← 10
    let y ← 20
    let tổng ← x + y
    print tổng

    # --- Reassign only biến bindings ---

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

Expected output:

0
1
11
Salve, Mundus!
30
Vale