設為
Translation status: 繁體中文 reader-locale proof. Term names and code fences follow the zh-Hant pack; supporting prose may still be English.
Declares an inferred immutable local.
Syntax: 設為 <name> [← <expression>]
Category#
binding
Related#
Examples#
radix/corpus/sit/sit.fab (canonical · keyword)#
Declares an inferred immutable local.
# =============================================================================
# 設為 — Declares an inferred immutable local.
# =============================================================================
#
# What this teaches:
# • Immutable binding sugar — `設為 name` is a compact alternative to
# `定值 _ name` for inferred-type immutable locals
# • Supports immediate init (`設為 x ← expr`) and deferred init
# (`設為 x` then `x ← expr` later)
#
# Common mistakes:
# • Confusing `設為` (sugar for `定值 _`) with `變值` — `設為` creates an immutable binding.
#
# See also: 定值, 變值, ←
# =============================================================================
# 設為 — inferred immutable bindings
#
# Immediate init:
# 設為 名稱 ← expr -- compact sugar for 定值 _ 名稱 ← expr
#
# Deferred init:
# 設為 名稱 -- compact sugar for 定值 _ 名稱 (assign once later)
# 名稱 ← expr
#
# Prefer 設為 when a block chains several inferred locals; keep 定值 _ when
# teaching the explicit infer marker or mixing typed and inferred bindings.
#
# GRAMMAR:
# sitDecl := '設為' IDENTIFIER ('←' expression)?
#
# EXPECTED OUTPUT:
# sit.expected
main {
let salve ← "Salve"
let 名稱 ← "Marcus"
let nuntius ← "§, §!"(salve, 名稱)
print nuntius
let label
label ← "deferred"
print label
const _ idem ← nuntius
print idem
}Expected output:
Salve, Marcus!
deferred
Salve, Marcus!