Renderingen-US

Cheat sheet

Short examples of how Faber is actually written. Every snippet on these pages compiles — they are checked against the compiler on each build, not typed from memory.

This is not the corpus. The corpus is the exhaustive reference: one page per keyword, every construct registered and measured. The cheat sheet is the opposite shape — a handful of pages, each showing the two or three ways people really write something.

The feel of the language#

Three signals do most of the work. Types come before names, behaviour words are Latin, and structure is carried by glyphs rather than punctuation soup.

reader locale
faber convert --to en — English reader surface
fn divide(int a, int b) → int ∪ none {
    if b ≡ 0 then return null
    return a / b
}
faber convert --to la — canonical Faber
functio divide(numerus a, numerus b) → numerus ∪ nihil {
    si b ≡ 0 ergo redde nulla
    redde a / b
}
faber convert --to th-TH — Thai
ฟังก์ชัน divide(จํานวน a, จํานวน b) → จํานวน ∪ นัล {
    ถ้า b ≡ 0 ดังนั้น คืน ว่างเปล่า
    คืน a / b
}
faber convert --to zh-Hans — Simplified Chinese
函数 divide(整数 a, 整数 b) → 整数 ∪ 空类型 {
    如果 b ≡ 0 则 返回 皆无
    返回 a / b
}
faber convert --to zh-Hant — Traditional Chinese
函式 divide(整數 a, 整數 b) → 整數 ∪ 無 {
    若 b ≡ 0 則 傳回 可空
    傳回 a / b
}
faber convert --to vi — Vietnamese
hàm divide(số a, số b) → số ∪ rỗng_ty {
    nếu b ≡ 0 do_đó trả không_gì
    trả a / b
}
faber convert --to ar — Arabic
دالة divide(عدد a, عدد b) → عدد ∪ نوع_لاشيء {
    إذا b ≡ 0 إذن أعد خال
    أعد a / b
}
faber convert --to hi — Hindi
फलन divide(संख्या a, संख्या b) → संख्या ∪ शून्य_मान {
    यदि b ≡ 0 अतः लौटाओ शून्यवत्
    लौटाओ a / b
}

int a — type first, then the name. → introduces the return type. ∪ joins types into a union, so this returns a number or nothing. ≡ is equality. return returns.

A whole program, doing real work:

reader locale
faber convert --to en — English reader surface
main {
    const list<f32> valores ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
    const tensor<f32, []> seed ← empty
    const tensor<f32, [2, 3]> matrix ← seed.from_flat(valores, [2, 3])
    const f32 medium ← matrix.mean()
    print medium
}
faber convert --to la — canonical Faber
incipit {
    fixum lista<f32> valores ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
    fixum tensor<f32, []> seed ← vacua
    fixum tensor<f32, [2, 3]> matrix ← seed.strue(valores, [2, 3])
    fixum f32 medium ← matrix.media()
    nota medium
}
faber convert --to th-TH — Thai
เริ่ม {
    คงที่ รายการ<f32> valores ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
    คงที่ เทนเซอร์<f32, []> seed ← เซตว่าง
    คงที่ เทนเซอร์<f32, [2, 3]> matrix ← seed.สร้างจากข้อมูลแบน(valores, [2, 3])
    คงที่ f32 medium ← matrix.ค่าเฉลี่ย()
    บันทึก medium
}
faber convert --to zh-Hans — Simplified Chinese
入口 {
    常量 列表<f32> valores ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
    常量 张量<f32, []> seed ← 空集
    常量 张量<f32, [2, 3]> matrix ← seed.由扁平构造(valores, [2, 3])
    常量 f32 medium ← matrix.均值()
    显示 medium
}
faber convert --to zh-Hant — Traditional Chinese
入口 {
    定值 列表<f32> valores ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
    定值 張量<f32, []> seed ← 空集
    定值 張量<f32, [2, 3]> matrix ← seed.由扁平建構(valores, [2, 3])
    定值 f32 medium ← matrix.平均值()
    註記 medium
}
faber convert --to vi — Vietnamese
bắt_đầu {
    hằng danh_sách<f32> valores ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
    hằng ten_xo<f32, []> seed ← tập_rỗng
    hằng ten_xo<f32, [2, 3]> matrix ← seed.dựng_từ_phẳng(valores, [2, 3])
    hằng f32 medium ← matrix.trung_bình()
    ghi_chú medium
}
faber convert --to ar — Arabic
بداية {
    ثابت قائمة<f32> valores ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
    ثابت موتر<f32, []> seed ← فارغ
    ثابت موتر<f32, [2, 3]> matrix ← seed.ابن_من_مسطح(valores, [2, 3])
    ثابت f32 medium ← matrix.المتوسط()
    اعرض medium
}
faber convert --to hi — Hindi
आरंभ {
    स्थिर सूची<f32> valores ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
    स्थिर टेंसर<f32, []> seed ← खाली
    स्थिर टेंसर<f32, [2, 3]> matrix ← seed.समतल_से_बनाओ(valores, [2, 3])
    स्थिर f32 medium ← matrix.माध्य()
    दिखाओ medium
}

main is the entry point. const binds a constant. ← is the bind glyph — assignment reads right-to-left into the name. print prints.

By topic#

PageWhat it covers
Entry pointsmain, async entry, CLI arguments and annotations
Bindingsconst vs var, type holes, union holes
Types and widthsNumbers and their widths, lists, tables, tensors, vectors, and the sugar for each
GenericsGeneric functions, generic containers, class
Loopsfor over values, keys, and ranges; while
Control flowif / elif / else, switch, match over unions
Errors and catchingThe ⇥ error channel, throw, and catch on many block forms
Conversions↦ conversion, recovery with ⊥, conversion vs casting
ImportsStandard library, local files, aliasing, and public re-exports
Reader localesThe same program in eight human languages, side by side
Testingdescribe, test, assert, tags, running tests
CommandsThe daily faber CLI loop

Keywords you will meet first#

The twenty that carry most Faber source. Each links to the page that shows it in use; the corpus has the exhaustive entry for every one.

KeywordMeansShown on
mainProgram entry pointEntry points
async_mainAsync program entry pointEntry points
fnDeclare a functionGenerics
returnReturn a valueControl flow
constBind a constantBindings
varBind a mutable variableBindings
classDeclare a record typeGenerics
typeName an alias for a typeTypes and widths
ifIfControl flow
elifElse-ifControl flow
elseElseControl flow
switchSelect over a valueControl flow
matchMatch over a unionControl flow
caseA case armControl flow
forIterateLoops
whileWhileLoops
throwSend a value down the error channelErrors and catching
catchCatch from the error channelErrors and catching
importImport a module or itemImports
testDeclare a testTesting

Glyphs#

GlyphReads as
←bind — put the value on the right into the name on the left
→returns this type
⇥…and may fail with this error type
≡equals
∪union of types
↦convert to this type
∴closure joint
‥range, as in 0‥10

Full discussion: Glyphs and Latin.