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