Renderingen-US

morphologia

Translation status: English reader-locale proof. Code fences render through the en pipeline; prose is canonical Latin.

Verb-form dispatch on collection methodi (imperative vs participle endings).

Syntax: <collection>.<verb-a|verb-ata|verb-e|verb-ita>(<args>)

Category#

collection

Examples#

radix/corpus/morphologia/morphologia.fab (canonical · concept)#

Verb-form dispatch on collection methodi (imperative vs participle endings).

# =============================================================================
# morphologia — Verb-form dispatch on collection methodi (imperative vs participle endings).
# =============================================================================
#
# What this teaches:
#   • verb-form dispatch — imperative endings (`-a`, `-e`, `-i`) mutate in place vs participle endings (`-ata`, `-ita`) return new values
#   • complete coverage of paired methods: filtra/filtrata, adde/addita, inverte/inversa, ordina/ordinata, mappa/mappata
#
# Common mistakes:
#   • Confusing imperative mutation forms (-a, -e, -i) with participle copy-returning forms (-ata, -ita) — imperatives mutate in place, participles return new values.
#
# See also: lista, appende, filtrata
# =============================================================================

# morphologia — verb-form dispatch on collection methods
#
# Imperative (-a, -e, -i): mutates in place  (appende, inverte, ordina)
# Participle (-ata, -ita):   returns new value (filtrata, addita, inversa)
#
# GRAMMAR:
#   methodCall :← expr '.' ident '(' … ')'   (verb ending selects semantics)
#
# EXPECTED OUTPUT:
#   filtrata nova: [2, 4]
#   addita nova: [1, 2, 3, 4, 5, 6]
#   appende mutat: [1, 2, 3, 4]
#   inversa nova: [5, 4, 3, 2, 1]
#   inverte mutat: [3, 2, 1]
#   ordinata nova: [1, 2, 3, 4, 5]
#   ordina mutat: [1, 2, 3]
#   mappata nova: [2, 4, 6, 8, 10]
#   res prima: [1, 2, 3, 4, 5]

main {
    var _ res  [1, 2, 3, 4, 5] ∷ list<int>

    # ≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
    # FILTRA: filtr-
    # ≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡

    # filtrata returns a new filtered list
    const _ pares  res.filtrata(int x ∴ x % 2  0)
    print "filtrata nova: §"(pares)

    # ≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
    # ADDE: adde-
    # ≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡

    # addita returns a new list with an added element
    const _ aucta  res.addita(6)
    print "addita nova: §"(aucta)

    # appende mutates in place
    var _ mutanda  [1, 2, 3]
    mutanda.appende(4)
    print "appende mutat: §"(mutanda)

    # ≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
    # INVERTE: invert-/invers-
    # ≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡

    # inversa returns a new reversed list
    const _ versa  res.inversa()
    print "inversa nova: §"(versa)

    # inverte mutates in place
    var _ invertenda  [1, 2, 3]
    invertenda.inverte()
    print "inverte mutat: §"(invertenda)

    # ≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
    # ORDINA: ordin-
    # ≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡

    # ordinata returns a new sorted list
    const _ ordinata  res.ordinata()
    print "ordinata nova: §"(ordinata)

    # ordina mutates in place
    var _ ordinanda  [3, 1, 2]
    ordinanda.ordina()
    print "ordina mutat: §"(ordinanda)

    # ≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
    # MAPPA: mapp-
    # ≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡

    # mappata returns a new mapped list
    const _ duplicata  res.mappata(int x ∴ x * 2)
    print "mappata nova: §"(duplicata)

    # ≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
    # Participle operations leave the original list unchanged
    # ≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
    print "res prima: §"(res)
}

Expected output:

filtrata nova: [2, 4]
addita nova: [1, 2, 3, 4, 5, 6]
appende mutat: [1, 2, 3, 4]
inversa nova: [5, 4, 3, 2, 1]
inverte mutat: [3, 2, 1]
ordinata nova: [1, 2, 3, 4, 5]
ordina mutat: [1, 2, 3]
mappata nova: [2, 4, 6, 8, 10]
res prima: [1, 2, 3, 4, 5]