rest
Translation status: English reader-locale proof. Term names and code fences follow the en pack; supporting prose may still be English.
Collects remaining parameters, operands, or extracted fields.
Aliases: rest
Syntax: rest <type> <name>
Category#
function
Related#
Examples#
radix/corpus/ceteri/ceteri.fab (canonical · keyword)#
Collects remaining parameters, operands, or extracted fields.
# =============================================================================
# rest — Collects remaining parameters, operands, or extracted fields.
# =============================================================================
#
# What this teaches:
# • Rest parameters — `rest <type> <name>` in a function signature collects
# all remaining arguments into a list
# • Variadic functions — `rest list<int> numeri` enables summing an
# arbitrary number of numeric arguments
#
# Common mistakes:
# • confusing `rest` (rest parameter collecting remaining args into a list) with `empty` (an empty collection initializer)
#
# See also: fn, operand, from
# =============================================================================
# rest — rest parameter (collects remaining arguments)
#
# fn <name>(rest <type> <name>) → <type>
#
# GRAMMAR:
# param :← 'rest' type ident
#
# EXPECTED OUTPUT:
# none
fn sum(rest list<int> numeri) → int {
var _ total ← 0
for from numeri const n {
total ← total + n
}
return total
}
main {
# rest receives the whole list
print sum([1, 2, 3, 4])
}Expected output:
10