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 format --locale en — English reader surface
fn divide(int a, int b)  int  null {
    if b  0 then return null
    return a / b
}
faber format --locale la — canonical Faber
functio divide(numerus a, numerus b)  numerus  nihil {
    si b  0 ergo redde nihil
    redde a / b
}
faber format --locale th-TH — Thai
ฟังก์ชัน divide(จำนวน a, จำนวน b)  จำนวน  ว่าง {
    ถ้า b  0 ดังนั้น คืน ว่าง
    คืน a / b
}
faber format --locale zh-Hans — Simplified Chinese
函数 divide(整数 a, 整数 b)  整数   {
    如果 b  0  返回 
    返回 a / b
}
faber format --locale zh-Hant — Traditional Chinese
函式 divide(整數 a, 整數 b)  整數   {
     b  0  傳回 
    傳回 a / b
}
faber format --locale vi — Vietnamese
hàm divide(số a, số b)  số  rỗng {
    nếu b  0 do_đó trả rỗng
    trả a / b
}
faber format --locale ar — Arabic
دالة divide(عدد a, عدد b)  عدد  لاشيء {
    إذا b  0 إذن أعد لاشيء
    أعد a / b
}
faber format --locale hi — Hindi
फलन divide(संख्या a, संख्या b)  संख्या  शून्य {
    यदि b  0 अतः लौटाओ शून्य
    लौटाओ a / b
}

numerus 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 format --locale 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  vacua
    const tensor<f32, [2, 3]> matrix  seed.strue(valores, [2, 3])
    const f32 medium  matrix.media()
    print medium
}
faber format --locale 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 format --locale th-TH — Thai
เริ่ม {
    คงที่ รายการ<f32> valores  [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
    คงที่ เทนเซอร์<f32, []> seed  เซตว่าง
    คงที่ เทนเซอร์<f32, [2, 3]> matrix  seed.strue(valores, [2, 3])
    คงที่ f32 medium  matrix.media()
    บันทึก medium
}
faber format --locale 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.strue(valores, [2, 3])
    常量 f32 medium  matrix.media()
    显示 medium
}
faber format --locale 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.strue(valores, [2, 3])
    定值 f32 medium  matrix.media()
    註記 medium
}
faber format --locale 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.strue(valores, [2, 3])
    hằng f32 medium  matrix.media()
    ghi_chú medium
}
faber format --locale ar — Arabic
بداية {
    ثابت قائمة<f32> valores  [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
    ثابت موتر<f32, []> seed  فارغ
    ثابت موتر<f32, [2, 3]> matrix  seed.strue(valores, [2, 3])
    ثابت f32 medium  matrix.media()
    اعرض medium
}
faber format --locale hi — Hindi
आरंभ {
    स्थिर सूची<f32> valores  [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
    स्थिर टेंसर<f32, []> seed  खाली
    स्थिर टेंसर<f32, [2, 3]> matrix  seed.strue(valores, [2, 3])
    स्थिर f32 medium  matrix.media()
    दिखाओ 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, iace, and catch on many block forms
Conversions conversion, recovery with , conversion vs casting
ImportsStandard library, local files, aliasing, publica vs privata
Reader localesThe same program in eight human languages, side by side
Testingprobandum, proba, adfirma, 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
incipietAsync program entry pointEntry points
fnDeclare a functionGenerics
returnReturn a valueControl flow
constBind a constantBindings
varBind a mutable variableBindings
classDeclare a record typeGenerics
typusName 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
iaceSend a value down the error channelErrors and catching
catchCatch from the error channelErrors and catching
importImport a module or itemImports
probaDeclare 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.