Renderingen-US

Experimental through version 1. Version 0 was alpha. This is the first language release: the interface is relatively stable, not frozen. Nothing is promised stable until version 2.

list

Translation status: English reader-locale proof. Term names and code fences follow the en pack; supporting prose may still be English.

A list range index copies the window between the bounds; an index past the end is checked at run time and aborts.

Aliases: array, list

Syntax: xs[<start>‥<end>]

Category#

list

Examples#

radix/corpus/reference/keyword/lista/lista.fab (canonical · keyword)#

Generic ordered collection type.

# =============================================================================
# list — Generic ordered collection type.
# =============================================================================
#
# What this teaches:
#   • list literal syntax — `[elem, ...]` with typed empty collections using `empty`
#   • the `spread` operator — splicing one list into another literal
#   • basic access: `longitudo()` and indexed reads via `[n]`
#
# Common mistakes:
#   • Using empty without an explicit type annotation — empty requires a declared collection type like list<T>.
#
# See also: map, set, ∷, for
# =============================================================================

# list<T> literals, empty, and spread (long-form types — default Faber readability).
# Numeric/tensor modules may use lf32/lu32 sugar; see docs/design/numeric-type-sugar.md.
#
# list<T> name ← empty        -- typed empty collection (forma innata)
# let _ name ← [elem, …]     -- list literal
# [spread expr, …]              -- splice into literal
#
# GRAMMAR:
#   listDecl :← ('mut' | 'let') 'list<' type '>' ident '←' expr
#   listLit  :← '[' (expr | spread)* ']'
#
# EXPECTED OUTPUT:
#   Scalar longitudo() and indexed accipe only (lista.expected).

main {
    let list<int> vacuares ← empty
    let _ numeri ← [1, 2, 3, 4, 5]
    let _ nomina ← ["Marcus", "Julia", "Gaius"]
    let _ vexilla ← [true, false, true]
    let _ matrix ← [[1, 2], [3, 4], [5, 6]]
    let list<int> primum ← [1, 2, 3]
    let list<int> secundum ← [4, 5, 6]
    let _ coniuncta ← [spread primum, spread secundum]
    let _ aucta ← [0, spread primum, 99]
    print vacuares.length()
    print numeri.length()
    print numeri[0]
    print numeri[4]
    print nomina.length()
    print nomina[1]
    print vexilla[0]
    print vexilla[2]
    print matrix.length()
    print matrix[1][0]
    print coniuncta.length()
    print aucta.length()
    print aucta[0]
    print aucta[4]
}

Expected output:

0
5
1
5
3
Julia
true
true
3
3
6
5
0
99

radix/corpus/reference/keyword/lista/methodi-copiae.fab (canonical · keyword)#

Generic ordered collection type.

# =============================================================================
# list — Generic ordered collection type.
# =============================================================================
#
# What this teaches:
#   • copy, slice, and reordering intrinsics — `addita()`, `sectio()`, `first()`, `ultima()`
#   • `mut list<int> mutata ← res[0‥2]` gets a new list containing the same
#     value elements. This is a shallow window copy: replacing a slot in
#     `mutata` does not replace a slot in `res`.
#   • ordering operations — `inversa()`, `sort()`
#
# Common mistakes:
#   • Forgetting that sectio(lo, hi) uses an exclusive hi bound — the returned slice may be shorter than expected.
#   • Assuming a window aliases the source list itself; it is a new list with
#     the same elements, not a view into the source's slots.
#
# See also: map, set, ∷, for
# =============================================================================

# list<T> copy, slice, and ordering intrinsics
#
# res.added(x) | res.slice(lo, hi) | res.take(n) | res.take_last(n)   -- copies
# res.drop(n) | res.invert() | res.sorted()                      -- reorder
#
# GRAMMAR:
#   listMethod :← expr '.' ('addita' | 'sectio' | 'first' | 'ultima'
#                         | 'omissa' | 'inversa' | 'sort') '(' args? ')'
#
# EXPECTED OUTPUT:
#   [1, 2, 3, 4, 5, 6]
#   [2, 3, 4]
#   [1, 2]
#   [4, 5]
#   [3, 4, 5]
#   [5, 4, 3, 2, 1]
#   [1, 2, 3]
#   [0]
#   [0]
#   [1, 2]
#   [99, 2]
#   [1, 2, 3, 4, 5]
#
# BACKEND: Go e2e whitelist — list intrinsic methods not yet lowered for Go
# (whitelist: list/methodi-copiae.fab).

main {
    let _ res ← [1, 2, 3, 4, 5] ∷ list<int>
    let _ addita ← res.added(6)
    let _ sectio ← res.slice(1, 4) ⊥ [0]
    let _ primaduo ← res.take(2) ⊥ [0]
    let _ ultimaduo ← res.take_last(2)
    let _ omissaduo ← res.drop(2)
    let _ inversa ← res.invert()
    let _ sort ← [3, 1, 2].sorted()
    print addita
    print sectio
    print primaduo
    print ultimaduo
    print omissaduo
    print inversa
    print sort
    let list<int> sectiofallax ← res.slice(1, 9) ⊥ [0]
    let list<int> primafallax ← res.take(9) ⊥ [0]
    let list<int> fenestra ← res[0 ‥ 2]
    mut list<int> mutata ← res[0 ‥ 2]
    mutata[0] ← 99
    print sectiofallax
    print primafallax
    print fenestra
    print mutata
    print res
}

Expected output:

[1, 2, 3, 4, 5, 6]
[2, 3, 4]
[1, 2]
[4, 5]
[3, 4, 5]
[5, 4, 3, 2, 1]
[1, 2, 3]
[0]
[0]
[1, 2]
[99, 2]
[1, 2, 3, 4, 5]

radix/corpus/reference/keyword/lista/methodi-mutatio.fab (canonical · keyword)#

Generic ordered collection type.

# =============================================================================
# list — Generic ordered collection type.
# =============================================================================
#
# What this teaches:
#   • mutation intrinsics for lists — `appende()`, `decapita()`, `detrahe()`, `inverte()`, `ordina()`
#   • contrast between mutation methods and copy-returning participle forms
#
# Common mistakes:
#   • Expecting mutation methods (appende, inverte, ordina) to return a new list — they mutate in place and do not return a value.
#
# See also: map, set, ∷, for
# =============================================================================

# list<T> mutation intrinsics
#
# res.append(x) | res.remove_first() | res.remove_last() | res.reverse() | res.sort()
#
# GRAMMAR:
#   listMethod :← expr '.' ('appende' | 'decapita' | 'detrahe' | 'inverte' | 'ordina') '(' args? ')'
#
# EXPECTED OUTPUT:
#   [1, 2]
#   3
#   4
#
# BACKEND: Go e2e whitelist — list intrinsic methods not yet lowered for Go
# (whitelist: list/methodi-mutatio.fab).

main {
    mut list<int> res ← [3, 1, 2] ∷ list<int>
    res.append(4)
    let int ∪ none primusremotus ← res.remove_first()
    let int ∪ none ultimusremotus ← res.remove_last()
    res.reverse()
    res.sort()
    print res
    print primusremotus
    print ultimusremotus
}

Expected output:

[1, 2]
3
4

radix/corpus/reference/keyword/lista/range-index-oob.fab (canonical · keyword)#

A list range index copies the window between the bounds; an index past the end is checked at run time and aborts.

# =============================================================================
# list — a range index copies a window; the bounds are checked at run time.
# =============================================================================
#
# What this teaches:
#   • Range index on a list — `xs[0‥n]` copies the elements from `0` up to
#     but not including `n` into a new list; both bounds may be computed at
#     run time.
#   • The bounds are checked at run time — `xs[0‥n]` with `mut int n ← 9`
#     is not a compile error: the bounds are values. The run prints its
#     earlier output, then aborts when the index is evaluated with
#     "list range 0‥9 outside 0‥3"; the program exits non-zero and the
#     rest of the body never runs.
#
# Common mistakes:
#   • Expecting a range index past the end to clamp to the list length or
#     yield an empty list — the window must lie inside `0‥len`.
#   • Expecting the out-of-bounds window to be a compile error — the bounds
#     are run-time values, so the check fires where the index is evaluated,
#     and earlier prints are already on stdout.
#   • Expecting the trap to be recoverable with `do … catch` — an implicit
#     index trap is not in the `⇥` channel.
#
# See also: list, numerus-overflow
# =============================================================================

# range-index-oob — a window past the end dies
#
# POLICY:
#   A list range index copies a copied window whose bounds must lie inside
#   `0‥len`; a window past the end is a run-time trap, not a compile error,
#   so it aborts the run where the index is evaluated.

main {
    let list<int> xs ← [10, 20, 30]
    mut int n ← 9
    print "before"
    print xs[0 ‥ n]
    print "after"
}

Expected output:

before

radix/corpus/reference/reject/lista/divide-reject.fab (supporting · reject)#

List / list is refused by name: the elementwise divisions are ⊘ and ÷.

# Dividing two lists with `/` is refused by name.
# The operator does not select elementwise division.
# The elementwise division forms have dedicated operators.
# This is a semantic rejection, not a parser limitation.

main {
    let list<int> a ← [4, 6, 8]
    let list<int> b ← [2, 3, 4]
    print a / b
}

Expected: compilation rejects this example.

radix/corpus/reference/reject/lista/elementwise-comparison-bits-reject.fab (supporting · reject)#

Ordering a list of bits is refused: a bits list has whole-value equality only.

# =============================================================================
# list — A list of bits has whole-value equality only.
# =============================================================================
#
# What this teaches:
#   • `≺ ≻ ≤ ≥` lift per element over numeric lists; bits are not numbers
#   • compare whole bits lists with `≡`, or convert the elements with `↦`
#
# Common mistakes:
#   • looking for a missing feature — a bits list is not ordered by design
#
# See also: elementwise-comparison, bits
# =============================================================================

# list reject case — expected compile failure
#
# This exemplum intentionally fails to compile.

main {
    let list<b8> xs ← [0x01, 0x02]
    let list<b8> ys ← [0x01, 0x03]
    print xs ≺ ys
}

Expected: compilation rejects this example.

radix/corpus/reference/reject/lista/exact-bound-lattice-decline.fab (supporting · reject)#

Decline: unequal exact bounds on literal elementwise operands reject during typecheck.

# =============================================================================
# Exact-bound list lattice — documented static decline.
# =============================================================================
#
# The two unannotated literals are exact witnesses of capacities 2 and 1.
# Elementwise `+` therefore rejects this mismatch at typecheck with the
# lista_capacity_mismatch issue. Dynamic `list<T>` operands defer their
# equal-length check to runtime; these literal operands do not.
#
# EXPECTED DECLINE: SEM011:lista_capacity_mismatch
# =============================================================================

main {
    let list<int> rejected ← [1, 2] + [3]
    print rejected
}

Expected: compilation rejects this example.

radix/corpus/reference/reject/lista/index-numerus-reject.fab (supporting · reject)#

A list index must be an integer: a text index is refused by name.

# list reject case — a text index on a list is refused.
# A list is addressed by an integer position; `xs["x"]` has no position.
# The checker names the issue `array_index_must_be_numerus`.
# This exemplum intentionally fails to check.

main {
    let list<int> xs ← [1, 2, 3]
    print xs["x"]
}

Expected: compilation rejects this example.

radix/corpus/reference/reject/lista/index-requires-collection-reject.fab (supporting · reject)#

Bracket indexing needs a list or a map; an integer cannot be indexed.

# Bracket indexing is refused for an integer because it is not a collection.
# Lists and maps support indexing; integers do not.
# The expression `n[0]` therefore fails during semantic checking.
# This exemplum intentionally demonstrates that rejection.

main {
    let int n ← 1
    print n[0]
}

Expected: compilation rejects this example.

radix/corpus/reference/reject/lista/multiply-reject.fab (supporting · reject)#

List * list is refused by name: the elementwise product is ⊙.

# Multiplying two lists with `*` is refused by name.
# The operator does not select elementwise multiplication.
# The elementwise product has a dedicated operator.
# This is a semantic rejection, not a parser limitation.

main {
    let list<int> a ← [1, 2, 3]
    let list<int> b ← [4, 5, 6]
    print a * b
}

Expected: compilation rejects this example.

radix/corpus/reference/reject/lista/spread-source-reject.fab (supporting · reject)#

A spread source must be a list; spreading an integer is refused.

# A spread source must be a list.
# `[spread 1]` is refused because an integer is not a list.
# The spread marker requires a list-valued source.
# This is a semantic rejection, not a parser limitation.

main {
    let _ xs ← [spread 1]
}

Expected: compilation rejects this example.

radix/corpus/reference/reject/lista/text-index-type-reject.fab (supporting · reject)#

A text index must be an integer or an integer range, never a text.

# list reject case — a text index on a string is refused.
# A string is addressed by an integer position or an integer window,
# never by text. The checker names `textus_index_must_be_numerus_or_range`.
# This exemplum intentionally fails to check.

main {
    let string s ← "abc"
    print s["x"]
}

Expected: compilation rejects this example.

radix/corpus/reference/reject/lista/unknown-method-reject.fab (supporting · reject)#

Calling a method a list does not have is refused by name.

# =============================================================================
# list — Calling a method a list does not have is refused by name.
# =============================================================================
#
# What this teaches:
#   • a list has a fixed method surface; `.frobnicate()` is not on it
#   • the checker names the unknown method instead of guessing a result type
#
# Common mistakes:
#   • misspelling a stdlib method — the refusal names the method, not a type
#
# See also: methodi-accessus, methodi-copiae
# =============================================================================

# list reject case — expected compile failure
#
# This exemplum intentionally fails to compile.

main {
    let list<int> xs ← [1]
    print xs.frobnicate()
}

Expected: compilation rejects this example.