Success return type and recoverable alternate-exit type in function signatures.
Syntax: functio <name>(<params>) → <type> | functio <name>(<params>) → <success> ⇥ <error>
Category
function
Related
Examples
examples/corpus/operatores/function-types.fab (canonical · operator-group)
Success return type and recoverable alternate-exit type in function signatures.
# operatores/function-types — → and ⇥
#
# GRAMMAR:
# funcType :← 'functio' ident '(' params ')' ('→' type)? ('⇥' type)?
#
# EXPECTED OUTPUT:
# salve, 5, 0
#
# BACKEND:
# Cross-ref functio/functio.fab and iace/functio-fallibilis.fab.
functio saluta() → textus {
redde "salve"
}
functio divide(numerus a, numerus b) → numerus ⇥ textus {
si b ≡ 0 ergo iace "division by zero"
redde a / b
}
functio tutum(numerus a, numerus b) → numerus {
fac {
redde divide(a, b)
}
cape err {
mone err
redde 0
}
}
incipit {
nota saluta()
nota tutum(10, 2)
nota tutum(10, 0)
}Expected output:
salve
5
0