Renderingla

Functions

Functions in Faber are declared with functio, using type-first parameter syntax and a glyph return type.

Basic syntax

functio twice(numerus n) → numerus {
    redde n
}

With an error channel:

functio parse(textus input) → numerus ⇥ textus {
    redde 0
}

Examples

# No parameters, no return
functio saluta() {
    nota "Salve, Mundus!"
}

# Parameter, no explicit return
functio dic(textus verbum) {
    nota verbum
}

# Parameter and return type
functio duplica(numerus n) → numerus {
    redde n * 2
}

# Multiple parameters
functio adde(numerus a, numerus b) → numerus {
    redde a + b
}

Return values

Use redde for normal returns:

functio porta(numerus x) → numerus {
    si x < 0 ∴ redde 0
    redde x * 2
}

Bare redde for vacuum return type:

functio tace() → vacuum {
    redde
}

Borrowing and mutability (de, in, ex)

Faber marks how a value is passed with short prepositions on parameters:

MarkerIntentTypical Rust lowering
(none)Owned valueT by value
deShared borrow (read-only)&T
inMutable borrow&mut T
exConsume (move into callee)T by move
# Shared borrow
functio imprime(de textus label) → vacuum {
    nota label
}

# Mutable borrow
functio duplica(in numerus value) → vacuum {
    value ← value * 2
}

# Consume
functio consume(ex textus buffer) → textus {
    redde buffer
}

# Owned
functio salve(textus nomen) → textus {
    redde "Salve, §!"(nomen)
}

The same words (de, ex) are reused in other constructs — do not read every ex as "consume":

SurfaceRole
de textus name on parameterShared borrow
in numerus count on parameterMutable borrow
ex textus buffer on parameterMove into callee
itera ex items fixum itemIterate values
itera de tabula fixum keyIterate keys
ex source fixum x, ceteri restDestructure fields
importa ex "path"Import from module

Entry point

The program entry point is incipit:

incipit {
    nota "ingressus"
}

CLI entry point

For CLI programs, incipit argumenta receives parsed command arguments:

@ cli "echo"
@ descriptio "Prints text"
@ operandus ceteri textus words
incipit argumenta args {
    itera ex args.words fixum word {
        nota word
    }
}

Passing mode — sponte

sponte marks a parameter that may be omitted by the caller:

functio connect(textus host, numerus port sponte) → vacuum {
    nota host
}