Bindings
Binding a name to a value. ← is the bind glyph: the value on the right goes
into the name on the left.
Constant or variable#
const binds once. var binds a name you intend to change.
faber convert --to en — English reader surfacemain {
const int limit ← 10
var int count ← 0
count ← count + 1
print limit, count
}faber convert --to la — canonical Faberincipit {
fixum numerus limit ← 10
varia numerus count ← 0
count ← count + 1
nota limit, count
}faber convert --to th-TH — Thaiเริ่ม {
คงที่ จำนวน limit ← 10
แปร จำนวน count ← 0
count ← count + 1
บันทึก limit, count
}faber convert --to zh-Hans — Simplified Chinese入口 {
常量 整数 limit ← 10
变量 整数 count ← 0
count ← count + 1
显示 limit, count
}faber convert --to zh-Hant — Traditional Chinese入口 {
定值 整數 limit ← 10
變值 整數 count ← 0
count ← count + 1
註記 limit, count
}faber convert --to vi — Vietnamesebắt_đầu {
hằng số limit ← 10
biến số count ← 0
count ← count + 1
ghi_chú limit, count
}faber convert --to ar — Arabicبداية {
ثابت عدد limit ← 10
متغير عدد count ← 0
count ← count + 1
اعرض limit, count
}faber convert --to hi — Hindiआरंभ {
स्थिर संख्या limit ← 10
चर संख्या count ← 0
count ← count + 1
दिखाओ limit, count
}Reassigning a const is a compile error, not a convention. Reach for const
first and widen to var only where the value genuinely moves.
Type holes#
_ is a type hole: the compiler infers one concrete type for the binding.
main {
const _ name ← "Marcus"
const _ 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 {
const string ∪ int mixed ← 7
const list<string ∪ int> both ← [1, "two", 3]
print mixed, both
}faber convert --to la — canonical Faberincipit {
fixum textus ∪ numerus mixed ← 7
fixum 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 {
hằng văn_bản ∪ số mixed ← 7
hằng 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ố ∪ rỗng_ty {
nếu res.độ_dài() ≡ 0 do_đó trả không_gì
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 record in one statement.
faber convert --to en — English reader surfaceclass Punctum {
const int x
const int y
}
main {
const _ p ← Punctum { x = 1, y = 2 }
const int x ← p.x
const int y ← p.y
print x, y
}faber convert --to la — canonical Fabergenus Punctum {
fixum numerus x
fixum numerus y
}
incipit {
fixum _ p ← Punctum { x = 1, y = 2 }
fixum numerus x ← p.x
fixum 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 {
hằng số x
hằng số y
}
bắt_đầu {
hằng _ p ← Punctum { x = 1, y = 2 }
hằng số x ← p.x
hằng 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
}Records 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