Bindings
Binding a name to a value. ← is the bind glyph: the value on the right goes
into the name on the left.
Fixed or writable#
let binds a name once. mut binds a name you intend to change.
main {
let int limit ← 10
mut int count ← 0
count ← count + 1
print limit, count
}Assigning a let name a second time is a compile error
(SEM020 immutable_second_assignment), not a convention. Reach for let
first and widen to mut only where the value genuinely moves. const is no
longer a run-time binding: it declares a compile-time fact with =, and a
run-time const int x ← 1 is PARSE010 runtime_const_retired.
Type holes#
_ is a type hole: the compiler infers one concrete type for the binding.
Every binding writes its type slot, so _ is how you ask for inference; there
is no short form, and let name ← "Marcus" is
PARSE010 binding_type_slot_required.
main {
let _ name ← "Marcus"
let _ numeri ← [1, 2, 3]
print name, numeri
}The hole infers a type; it does not make the binding dynamic. name is
string from this point on.
Union types and holes#
An inline A ∪ B in type position names its union members explicitly. A
standalone ∪ is a union hole: the compiler infers a finite set of member
types rather than one.
faber convert --to en — English reader surfacemain {
let string ∪ int mixed ← 7
let list<string ∪ int> both ← [1, "two", 3]
print mixed, both
}faber convert --to la — canonical Faberincipit {
sit textus ∪ numerus mixed ← 7
sit lista<textus ∪ numerus> both ← [1, "two", 3]
nota mixed, both
}faber convert --to th-TH — Thaiเริ่ม {
กำหนด ข้อความ ∪ จํานวน mixed ← 7
กำหนด รายการ<ข้อความ ∪ จํานวน> both ← [1, "two", 3]
บันทึก mixed, both
}faber convert --to zh-Hans — Simplified Chinese入口 {
设 文本 ∪ 整数 mixed ← 7
设 列表<文本 ∪ 整数> both ← [1, "two", 3]
显示 mixed, both
}faber convert --to zh-Hant — Traditional Chinese入口 {
設為 文字 ∪ 整數 mixed ← 7
設為 列表<文字 ∪ 整數> both ← [1, "two", 3]
註記 mixed, both
}faber convert --to vi — Vietnamesebắt_đầu {
đặt văn_bản ∪ số mixed ← 7
đặt danh_sách<văn_bản ∪ số> both ← [1, "two", 3]
ghi_chú mixed, both
}faber convert --to ar — Arabicبداية {
ليكن نص ∪ عدد mixed ← 7
ليكن قائمة<نص ∪ عدد> both ← [1, "two", 3]
اعرض mixed, both
}faber convert --to hi — Hindiआरंभ {
बैठा पाठ ∪ संख्या mixed ← 7
बैठा सूची<पाठ ∪ संख्या> both ← [1, "two", 3]
दिखाओ mixed, both
}Read a union out with match,
which forces every arm to be handled.
Optional values#
T ∪ none is the optional shape. It is an ordinary union whose other member
is nothing — Faber has no separate nullable syntax.
faber convert --to en — English reader surfacefn primum(list<int> res) → int ∪ none {
if res.length() ≡ 0 then return null
return res[0]
}
main {
print primum([1, 2, 3])
}faber convert --to la — canonical Faberfunctio primum(lista<numerus> res) → numerus ∪ nihil {
si res.longitudo() ≡ 0 ergo redde nulla
redde res[0]
}
incipit {
nota primum([1, 2, 3])
}faber convert --to th-TH — Thaiฟังก์ชัน primum(รายการ<จํานวน> res) → จํานวน ∪ ไม่มี {
ถ้า res.ความยาว() ≡ 0 ดังนั้น คืน ขาดหาย
คืน res[0]
}
เริ่ม {
บันทึก primum([1, 2, 3])
}faber convert --to zh-Hans — Simplified Chinese函数 primum(列表<整数> res) → 整数 ∪ 无 {
如果 res.长度() ≡ 0 则 返回 缺失
返回 res[0]
}
入口 {
显示 primum([1, 2, 3])
}faber convert --to zh-Hant — Traditional Chinese函式 primum(列表<整數> res) → 整數 ∪ 無 {
若 res.長度() ≡ 0 則 傳回 缺失
傳回 res[0]
}
入口 {
註記 primum([1, 2, 3])
}faber convert --to vi — Vietnamesehàm primum(danh_sách<số> res) → số ∪ hư_không {
nếu res.độ_dài() ≡ 0 do_đó trả vắng
trả res[0]
}
bắt_đầu {
ghi_chú primum([1, 2, 3])
}faber convert --to ar — Arabicدالة primum(قائمة<عدد> res) → عدد ∪ لاشيء {
إذا res.طول() ≡ 0 إذن أعد غائب
أعد res[0]
}
بداية {
اعرض primum([1, 2, 3])
}faber convert --to hi — Hindiफलन primum(सूची<संख्या> res) → संख्या ∪ कुछनहीं {
यदि res.लंबाई() ≡ 0 अतः लौटाओ अभाव
लौटाओ res[0]
}
आरंभ {
दिखाओ primum([1, 2, 3])
}Destructuring#
from pulls named fields out of a class value in one statement.
faber convert --to en — English reader surfaceclass Punctum {
let int x
let int y
}
main {
let _ p ← Punctum { x = 1, y = 2 }
let int x ← p.x
let int y ← p.y
print x, y
}faber convert --to la — canonical Fabergenus Punctum {
sit numerus x
sit numerus y
}
incipit {
sit _ p ← Punctum { x = 1, y = 2 }
sit numerus x ← p.x
sit numerus y ← p.y
nota x, y
}faber convert --to th-TH — Thaiชนิด Punctum {
กำหนด จํานวน x
กำหนด จํานวน y
}
เริ่ม {
กำหนด _ p ← Punctum { x = 1, y = 2 }
กำหนด จํานวน x ← p.x
กำหนด จํานวน y ← p.y
บันทึก x, y
}faber convert --to zh-Hans — Simplified Chinese类 Punctum {
设 整数 x
设 整数 y
}
入口 {
设 _ p ← Punctum { x = 1, y = 2 }
设 整数 x ← p.x
设 整数 y ← p.y
显示 x, y
}faber convert --to zh-Hant — Traditional Chinese類型 Punctum {
設為 整數 x
設為 整數 y
}
入口 {
設為 _ p ← Punctum { x = 1, y = 2 }
設為 整數 x ← p.x
設為 整數 y ← p.y
註記 x, y
}faber convert --to vi — Vietnamesekiểu Punctum {
đặt số x
đặt số y
}
bắt_đầu {
đặt _ p ← Punctum { x = 1, y = 2 }
đặt số x ← p.x
đặt số y ← p.y
ghi_chú x, y
}faber convert --to ar — Arabicصنف Punctum {
ليكن عدد x
ليكن عدد y
}
بداية {
ليكن _ p ← Punctum { x = 1, y = 2 }
ليكن عدد x ← p.x
ليكن عدد y ← p.y
اعرض x, y
}faber convert --to hi — Hindiवर्ग Punctum {
बैठा संख्या x
बैठा संख्या y
}
आरंभ {
बैठा _ p ← Punctum { x = 1, y = 2 }
बैठा संख्या x ← p.x
बैठा संख्या y ← p.y
दिखाओ x, y
}Class values are built with named fields in braces, not positional arguments — so adding a field never silently reorders an existing call site.
Related: Types and widths · Control flow