设
Translation status: 简体中文 reader-locale proof. Term names and code fences follow the zh-Hans 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!