渲染zh-Hant

ceteri

Translation status: 繁體中文 reader-locale proof. Code fences render through the zh-Hant pipeline; prose is canonical Latin.

Collects remaining parameters, operands, or extracted fields.

Aliases: rest

Syntax: ceteri <type> <name>

Category#

function

Examples#

radix/corpus/ceteri/ceteri.fab (canonical · keyword)#

Collects remaining parameters, operands, or extracted fields.

# =============================================================================
# ceteri — Collects remaining parameters, operands, or extracted fields.
# =============================================================================
#
# What this teaches:
#   • Rest parameters — `ceteri <type> <name>` in a function signature collects
#     all remaining arguments into a list
#   • Variadic functions — `ceteri lista<numerus> numeri` enables summing an
#     arbitrary number of numeric arguments
#
# Common mistakes:
#   • confusing `ceteri` (rest parameter collecting remaining args into a list) with `vacua` (an empty collection initializer)
#
# See also: functio, operandus, ex
# =============================================================================

# ceteri — rest parameter (collects remaining arguments)
#
# functio <nomen>(ceteri <typus> <nomen>) → <typus>
#
# GRAMMAR:
#   param :← 'ceteri' type ident
#
# EXPECTED OUTPUT:
#   none

fn summa(rest list<int> numeri)  int {
    var _ total  0

    for from numeri const n {
        total  total + n
    }

    return total
}

main {
    # ceteri receives the whole lista
    print summa([1, 2, 3, 4])
}

Expected output:

10