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.
faber convert --to en — English reader surfacefn divide(int a, int b) → int ∪ none {
if b ≡ 0 then return null
return a / b
}faber convert --to la — canonical Faberfunctio 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 — Vietnamesehàm divide(số a, số b) → số ∪ hư_không {
nếu b ≡ 0 do_đó trả vắng
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:
faber convert --to en — English reader surfacemain {
let list<f32> valores ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
let tensor<f32, [2, 3]> matrix ← valores ↦ tensor<f32, [2, 3]>
let f32 medium ← matrix.mean()
print medium
}faber convert --to la — canonical Faberincipit {
sit lista<f32> valores ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
sit tensor<f32, [2, 3]> matrix ← valores ↦ tensor<f32, [2, 3]>
sit 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, [2, 3]> matrix ← valores ↦ เทนเซอร์<f32, [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, [2, 3]> matrix ← valores ↦ 张量<f32, [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, [2, 3]> matrix ← valores ↦ 張量<f32, [2, 3]>
設為 f32 medium ← matrix.平均值()
註記 medium
}faber convert --to vi — Vietnamesebắt_đầu {
đặt danh_sách<f32> valores ← [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
đặt ten_xo<f32, [2, 3]> matrix ← valores ↦ ten_xo<f32, [2, 3]>
đặt 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, [2, 3]> matrix ← valores ↦ موتر<f32, [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, [2, 3]> matrix ← valores ↦ टेंसर<f32, [2, 3]>
बैठा f32 medium ← matrix.माध्य()
दिखाओ medium
}main is the entry point. let binds a fixed name. ← is the bind glyph —
assignment reads right-to-left into the name. print prints.
By topic#
| Page | What it covers |
|---|---|
| Entry points | main, async entry, CLI arguments and annotations |
| Bindings | let vs mut, type holes, union holes |
| Types and widths | Numbers and their widths, lists, tables, tensors, vectors, and the sugar for each |
| Generics | Generic functions, generic containers, class |
| Loops | for over values, keys, and ranges; while |
| Control flow | if / elif / else, switch, match over unions |
| Errors and catching | The ⇥ error channel, throw, and catch on many block forms |
| Conversions | ↦ conversion, recovery with ⊥, conversion vs casting |
| Imports | Standard library, local files, aliasing, and public re-exports |
| Reader locales | The same program in eight human languages, side by side |
| Testing | describe, test, assert, tags, running tests |
| Commands | The 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.
| Keyword | Means | Shown on |
|---|---|---|
main | Program entry point | Entry points |
async_main | Async program entry point | Entry points |
fn | Declare a function | Generics |
return | Return a value | Control flow |
let | Bind a fixed name | Bindings |
mut | Bind a writable name | Bindings |
class | Declare a record type | Generics |
type | Name an alias for a type | Types and widths |
if | If | Control flow |
elif | Else-if | Control flow |
else | Else | Control flow |
switch | Select over a value | Control flow |
match | Match over a union | Control flow |
case | A case arm | Control flow |
for | Iterate | Loops |
while | While | Loops |
throw | Send a value down the error channel | Errors and catching |
catch | Catch from the error channel | Errors and catching |
import | Import a module or item | Imports |
test | Declare a test | Testing |
Glyphs#
| Glyph | Reads 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.