แปร
Translation status: ภาษาไทย reader-locale proof. Term names and code fences follow the th-TH 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