Renderingen-US

Experimental through version 1. Version 0 was alpha. This is the first language release: the interface is relatively stable, not frozen. Nothing is promised stable until version 2.

Generics

Generic functions#

Type parameters go in angle brackets after the name.

reader locale
faber convert --to en — English reader surface
fn identitas<T>(T datum) → T {
    return datum
}

main {
    print identitas("Marcus")
    print identitas(42)
}
faber convert --to la — canonical Faber
functio identitas<T>(T datum) → T {
    redde datum
}

incipit {
    nota identitas("Marcus")
    nota identitas(42)
}
faber convert --to th-TH — Thai
ฟังก์ชัน identitas<T>(T datum) → T {
    คืน datum
}

เริ่ม {
    บันทึก identitas("Marcus")
    บันทึก identitas(42)
}
faber convert --to zh-Hans — Simplified Chinese
函数 identitas<T>(T datum) → T {
    返回 datum
}

入口 {
    显示 identitas("Marcus")
    显示 identitas(42)
}
faber convert --to zh-Hant — Traditional Chinese
函式 identitas<T>(T datum) → T {
    傳回 datum
}

入口 {
    註記 identitas("Marcus")
    註記 identitas(42)
}
faber convert --to vi — Vietnamese
hàm identitas<T>(T datum) → T {
    trả datum
}

bắt_đầu {
    ghi_chú identitas("Marcus")
    ghi_chú identitas(42)
}
faber convert --to ar — Arabic
دالة identitas<T>(T datum) → T {
    أعد datum
}

بداية {
    اعرض identitas("Marcus")
    اعرض identitas(42)
}
faber convert --to hi — Hindi
फलन identitas<T>(T datum) → T {
    लौटाओ datum
}

आरंभ {
    दिखाओ identitas("Marcus")
    दिखाओ identitas(42)
}

The same function serves both calls. T is fixed per call site, not erased to a dynamic value.

Generic with a union return#

Type parameters compose with unions, which is how "maybe nothing" is expressed generically.

reader locale
faber convert --to en — English reader surface
fn primum<T>(list<T> res) → T ∪ 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<T>(lista<T> res) → T ∪ nihil {
    si res.longitudo() ≡ 0 ergo redde nulla
    redde res[0]
}

incipit {
    nota primum([1, 2, 3])
}
faber convert --to th-TH — Thai
ฟังก์ชัน primum<T>(รายการ<T> res) → T ∪ ไม่มี {
    ถ้า res.ความยาว() ≡ 0 ดังนั้น คืน ขาดหาย
    คืน res[0]
}

เริ่ม {
    บันทึก primum([1, 2, 3])
}
faber convert --to zh-Hans — Simplified Chinese
函数 primum<T>(列表<T> res) → T ∪ 无 {
    如果 res.长度() ≡ 0 则 返回 缺失
    返回 res[0]
}

入口 {
    显示 primum([1, 2, 3])
}
faber convert --to zh-Hant — Traditional Chinese
函式 primum<T>(列表<T> res) → T ∪ 無 {
    若 res.長度() ≡ 0 則 傳回 缺失
    傳回 res[0]
}

入口 {
    註記 primum([1, 2, 3])
}
faber convert --to vi — Vietnamese
hàm primum<T>(danh_sách<T> res) → T ∪ hư_không {
    nếu res.độ_dài() ≡ 0 do_đó trả vắng
    trả res[0]
}

bắt_đầu {
    ghi_chú primum([1, 2, 3])
}
faber convert --to ar — Arabic
دالة primum<T>(قائمة<T> res) → T ∪ لاشيء {
    إذا res.طول() ≡ 0 إذن أعد غائب
    أعد res[0]
}

بداية {
    اعرض primum([1, 2, 3])
}
faber convert --to hi — Hindi
फलन primum<T>(सूची<T> res) → T ∪ कुछनहीं {
    यदि res.लंबाई() ≡ 0 अतः लौटाओ अभाव
    लौटाओ res[0]
}

आरंभ {
    दिखाओ primum([1, 2, 3])
}

Generic containers#

The built-in collections are generic already.

reader locale
faber convert --to en — English reader surface
main {
    let list<string> nomina ← ["Marcus", "Julia"]
    let map<string, int> aetates ← { "Marcus": 30 }
    print nomina, aetates
}
faber convert --to la — canonical Faber
incipit {
    sit lista<textus> nomina ← ["Marcus", "Julia"]
    sit tabula<textus, numerus> aetates ← { "Marcus": 30 }
    nota nomina, aetates
}
faber convert --to th-TH — Thai
เริ่ม {
    กำหนด รายการ<ข้อความ> nomina ← ["Marcus", "Julia"]
    กำหนด ตาราง<ข้อความ, จํานวน> aetates ← { "Marcus": 30 }
    บันทึก nomina, aetates
}
faber convert --to zh-Hans — Simplified Chinese
入口 {
    设 列表<文本> nomina ← ["Marcus", "Julia"]
    设 映射<文本, 整数> aetates ← { "Marcus": 30 }
    显示 nomina, aetates
}
faber convert --to zh-Hant — Traditional Chinese
入口 {
    設為 列表<文字> nomina ← ["Marcus", "Julia"]
    設為 表格<文字, 整數> aetates ← { "Marcus": 30 }
    註記 nomina, aetates
}
faber convert --to vi — Vietnamese
bắt_đầu {
    đặt danh_sách<văn_bản> nomina ← ["Marcus", "Julia"]
    đặt bảng<văn_bản, số> aetates ← { "Marcus": 30 }
    ghi_chú nomina, aetates
}
faber convert --to ar — Arabic
بداية {
    ليكن قائمة<نص> nomina ← ["Marcus", "Julia"]
    ليكن جدول<نص, عدد> aetates ← { "Marcus": 30 }
    اعرض nomina, aetates
}
faber convert --to hi — Hindi
आरंभ {
    बैठा सूची<पाठ> nomina ← ["Marcus", "Julia"]
    बैठा तालिका<पाठ, संख्या> aetates ← { "Marcus": 30 }
    दिखाओ nomina, aetates
}

Classes#

class (en class) declares a class with type-first fields. Each field names its mode: let is fixed after construction and mut is writable. A field with neither word is PARSE010 field_modifier_missing, and a ref field is PARSE010 ref_field_refused.

class Persona {
    let string nomen
    let int aetas
}

fn description(Persona p) → string {
    return p.nomen
}

main {
    let _ p ← Persona { nomen = "Marcus", aetas = 30 }
    print description(p)
}

Functions on a class#

A class can carry functions alongside its fields.

class Punctum {
    let int x
    let int y

    fn sum() → int {
        return self.x + self.y
    }
}

main {
    let _ p ← Punctum { x = 1, y = 2 }
    print p.summa()
}

self — "I" — is the receiver, what other languages spell this or self.

Related: Types and widths · Functions and flow