Renderingen-US

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.

reader locale
faber convert --to en — English reader surface
main {
    const int limit ← 10
    var int count ← 0
    count ← count + 1
    print limit, count
}
faber convert --to la — canonical Faber
incipit {
    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 — Vietnamese
bắ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.

reader locale
faber convert --to en — English reader surface
main {
    const string ∪ int mixed ← 7
    const list<string ∪ int> both ← [1, "two", 3]
    print mixed, both
}
faber convert --to la — canonical Faber
incipit {
    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 — Vietnamese
bắ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.

reader locale
faber convert --to en — English reader surface
fn 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 Faber
functio 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 — Vietnamese
hà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.

reader locale
faber convert --to en — English reader surface
class 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 Faber
genus 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 — Vietnamese
kiể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