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 format --locale en — English reader surfacemain {
const int limit ← 10
var int count ← 0
count ← count + 1
print limit, count
}faber format --locale la — canonical Faberincipit {
fixum numerus limit ← 10
varia numerus count ← 0
count ← count + 1
nota limit, count
}faber format --locale th-TH — Thaiเริ่ม {
คงที่ จำนวน limit ← 10
แปร จำนวน count ← 0
count ← count + 1
บันทึก limit, count
}faber format --locale zh-Hans — Simplified Chinese入口 {
常量 整数 limit ← 10
变量 整数 count ← 0
count ← count + 1
显示 limit, count
}faber format --locale zh-Hant — Traditional Chinese入口 {
定值 整數 limit ← 10
變值 整數 count ← 0
count ← count + 1
註記 limit, count
}faber format --locale vi — Vietnamesebắt_đầu {
hằng số limit ← 10
biến số count ← 0
count ← count + 1
ghi_chú limit, count
}faber format --locale ar — Arabicبداية {
ثابت عدد limit ← 10
متغير عدد count ← 0
count ← count + 1
اعرض limit, count
}faber format --locale 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.
faber format --locale en — English reader surfacemain {
const string nomen ← "Marcus"
const list<int> numeri ← [1, 2, 3]
print nomen, numeri
}faber format --locale la — canonical Faberincipit {
fixum textus nomen ← "Marcus"
fixum lista<numerus> numeri ← [1, 2, 3]
nota nomen, numeri
}faber format --locale th-TH — Thaiเริ่ม {
คงที่ ข้อความ nomen ← "Marcus"
คงที่ รายการ<จำนวน> numeri ← [1, 2, 3]
บันทึก nomen, numeri
}faber format --locale zh-Hans — Simplified Chinese入口 {
常量 文本 nomen ← "Marcus"
常量 列表<整数> numeri ← [1, 2, 3]
显示 nomen, numeri
}faber format --locale zh-Hant — Traditional Chinese入口 {
定值 文字 nomen ← "Marcus"
定值 列表<整數> numeri ← [1, 2, 3]
註記 nomen, numeri
}faber format --locale vi — Vietnamesebắt_đầu {
hằng văn_bản nomen ← "Marcus"
hằng danh_sách<số> numeri ← [1, 2, 3]
ghi_chú nomen, numeri
}faber format --locale ar — Arabicبداية {
ثابت نص nomen ← "Marcus"
ثابت قائمة<عدد> numeri ← [1, 2, 3]
اعرض nomen, numeri
}faber format --locale hi — Hindiआरंभ {
स्थिर पाठ nomen ← "Marcus"
स्थिर सूची<संख्या> numeri ← [1, 2, 3]
दिखाओ nomen, numeri
}The hole infers a type; it does not make the binding dynamic. nomen is
string from this point on.
Union holes#
∪ in type position is a union hole — the binding admits a finite set of
types rather than one.
faber format --locale en — English reader surfacemain {
const string ∪ int mixed ← 7
const list<string ∪ int> both ← [1, "two", 3]
print mixed, both
}faber format --locale la — canonical Faberincipit {
fixum textus ∪ numerus mixed ← 7
fixum lista<textus ∪ numerus> both ← [1, "two", 3]
nota mixed, both
}faber format --locale th-TH — Thaiเริ่ม {
คงที่ ข้อความ ∪ จำนวน mixed ← 7
คงที่ รายการ<ข้อความ ∪ จำนวน> both ← [1, "two", 3]
บันทึก mixed, both
}faber format --locale zh-Hans — Simplified Chinese入口 {
常量 文本 ∪ 整数 mixed ← 7
常量 列表<文本 ∪ 整数> both ← [1, "two", 3]
显示 mixed, both
}faber format --locale zh-Hant — Traditional Chinese入口 {
定值 文字 ∪ 整數 mixed ← 7
定值 列表<文字 ∪ 整數> both ← [1, "two", 3]
註記 mixed, both
}faber format --locale 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 format --locale ar — Arabicبداية {
ثابت نص ∪ عدد mixed ← 7
ثابت قائمة<نص ∪ عدد> both ← [1, "two", 3]
اعرض mixed, both
}faber format --locale 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 ∪ nihil is the optional shape. It is an ordinary union whose other member
is nothing — Faber has no separate nullable syntax.
faber format --locale en — English reader surfacefn primum(list<int> res) → int ∪ null {
if res.longitudo() ≡ 0 then return null
return res[0]
}
main {
print primum([1, 2, 3])
}faber format --locale la — canonical Faberfunctio primum(lista<numerus> res) → numerus ∪ nihil {
si res.longitudo() ≡ 0 ergo redde nihil
redde res[0]
}
incipit {
nota primum([1, 2, 3])
}faber format --locale th-TH — Thaiฟังก์ชัน primum(รายการ<จำนวน> res) → จำนวน ∪ ว่าง {
ถ้า res.longitudo() ≡ 0 ดังนั้น คืน ว่าง
คืน res[0]
}
เริ่ม {
บันทึก primum([1, 2, 3])
}faber format --locale zh-Hans — Simplified Chinese函数 primum(列表<整数> res) → 整数 ∪ 空 {
如果 res.longitudo() ≡ 0 则 返回 空
返回 res[0]
}
入口 {
显示 primum([1, 2, 3])
}faber format --locale zh-Hant — Traditional Chinese函式 primum(列表<整數> res) → 整數 ∪ 空 {
若 res.longitudo() ≡ 0 則 傳回 空
傳回 res[0]
}
入口 {
註記 primum([1, 2, 3])
}faber format --locale vi — Vietnamesehàm primum(danh_sách<số> res) → số ∪ rỗng {
nếu res.longitudo() ≡ 0 do_đó trả rỗng
trả res[0]
}
bắt_đầu {
ghi_chú primum([1, 2, 3])
}faber format --locale ar — Arabicدالة primum(قائمة<عدد> res) → عدد ∪ لاشيء {
إذا res.longitudo() ≡ 0 إذن أعد لاشيء
أعد res[0]
}
بداية {
اعرض primum([1, 2, 3])
}faber format --locale hi — Hindiफलन primum(सूची<संख्या> res) → संख्या ∪ शून्य {
यदि res.longitudo() ≡ 0 अतः लौटाओ शून्य
लौटाओ res[0]
}
आरंभ {
दिखाओ primum([1, 2, 3])
}Destructuring#
from pulls named fields out of a record in one statement.
faber format --locale en — English reader surfaceclass Punctum {
int x
int y
}
main {
const Punctum p ← Punctum {x = 1, y = 2}
const int x ← p.x
const int y ← p.y
print x, y
}faber format --locale la — canonical Fabergenus Punctum {
numerus x
numerus y
}
incipit {
fixum Punctum p ← Punctum {x = 1, y = 2}
fixum numerus x ← p.x
fixum numerus y ← p.y
nota x, y
}faber format --locale th-TH — Thaiชนิด Punctum {
จำนวน x
จำนวน y
}
เริ่ม {
คงที่ Punctum p ← Punctum {x = 1, y = 2}
คงที่ จำนวน x ← p.x
คงที่ จำนวน y ← p.y
บันทึก x, y
}faber format --locale zh-Hans — Simplified Chinese类 Punctum {
整数 x
整数 y
}
入口 {
常量 Punctum p ← Punctum {x = 1, y = 2}
常量 整数 x ← p.x
常量 整数 y ← p.y
显示 x, y
}faber format --locale zh-Hant — Traditional Chinese類型 Punctum {
整數 x
整數 y
}
入口 {
定值 Punctum p ← Punctum {x = 1, y = 2}
定值 整數 x ← p.x
定值 整數 y ← p.y
註記 x, y
}faber format --locale vi — Vietnamesekiểu Punctum {
số x
số y
}
bắt_đầu {
hằng Punctum p ← Punctum {x = 1, y = 2}
hằng số x ← p.x
hằng số y ← p.y
ghi_chú x, y
}faber format --locale ar — Arabicصنف Punctum {
عدد x
عدد y
}
بداية {
ثابت Punctum p ← Punctum {x = 1, y = 2}
ثابت عدد x ← p.x
ثابت عدد y ← p.y
اعرض x, y
}faber format --locale hi — Hindiवर्ग Punctum {
संख्या x
संख्या y
}
आरंभ {
स्थिर Punctum 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