Kết xuấtvi

danh_sách

Translation status: Tiếng Việt reader-locale proof. Term names and code fences follow the vi pack; supporting prose may still be English.

Generic ordered collection type.

Aliases: array, list

Syntax: danh_sách<T>

Category#

collection

Examples#

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

Generic ordered collection type.

# =============================================================================
# danh_sách — Generic ordered collection type.
# =============================================================================
#
# What this teaches:
#   • danh_sách literal syntax — `[elem, ...]` with typed empty collections using `tập_rỗng`
#   • the `rải` operator — splicing one list into another literal
#   • basic access: `longitudo()` and indexed reads via `[n]`
#
# Common mistakes:
#   • Using tập_rỗng without an explicit type annotation — tập_rỗng requires a declared collection type like danh_sách<T>.
#
# See also: bảng, tập_hợp, ∷, lặp
# =============================================================================

# danh_sách<T> literals, tập_rỗng, and rải (long-form types — default Faber readability).
# Numeric/tensor modules may use lf32/lu32 sugar; see docs/design/numeric-type-sugar.md.
#
# danh_sách<T> tên ← tập_rỗng        -- typed empty collection (forma innata)
# hằng _ tên ← [elem, …]     -- list literal
# [rải expr, …]              -- splice into literal
#
# GRAMMAR:
#   listDecl :← ('biến' | 'hằng') 'danh_sách<' type '>' ident '←' expr
#   listLit  :← '[' (expr | rải)* ']'
#
# EXPECTED OUTPUT:
#   Scalar longitudo() and indexed accipe only (lista.expected).

main {
    const list<int> vacuares ← empty
    const _ numeri ← [1, 2, 3, 4, 5]
    const _ nomina ← ["Marcus", "Julia", "Gaius"]
    const _ vexilla ← [true, false, true]
    const _ ma_trận ← [[1, 2], [3, 4], [5, 6]]
    const list<int> primum ← [1, 2, 3]
    const list<int> secundum ← [4, 5, 6]
    const _ coniuncta ← [spread primum, spread secundum]
    const _ 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 ma_trận[1][0]
    print coniuncta.length()
    print aucta.length()
    print aucta[0]
    print aucta[4]
}

Expected output:

0
5
1
5
3
Julia
verum
verum
3
3
6
5
0
99

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

Generic ordered collection type.

# =============================================================================
# danh_sách — Generic ordered collection type.
# =============================================================================
#
# What this teaches:
#   • sao_chép, slice, and reordering intrinsics — `addita()`, `sectio()`, `prima()`, `ultima()`
#   • ordering operations — `inversa()`, `ordinata()`
#
# Common mistakes:
#   • Forgetting that sectio(lo, hi) uses an exclusive hi bound — the returned slice may be shorter than expected.
#
# See also: bảng, tập_hợp, ∷, lặp
# =============================================================================

# danh_sách<T> sao_chép, slice, and ordering intrinsics
#
# res.added(x) | res.slice(lo, hi) | res.take(n) | res.take_last(n)   -- views
# res.drop(n) | res.invert() | res.sorted()                      -- reorder
#
# GRAMMAR:
#   listMethod :← expr '.' ('addita' | 'sectio' | 'prima' | 'ultima'
#                         | 'omissa' | 'inversa' | 'ordinata') '(' 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]
#
# BACKEND: Go e2e whitelist — danh_sách intrinsic methods not yet lowered for Go
# (whitelist: danh_sách/methodi-copiae.fab).

main {
    const _ res ← [1, 2, 3, 4, 5] ∷ list<int>
    const _ addita ← res.added(6)
    const _ sectio ← res.slice(1, 4)
    const _ primaduo ← res.take(2)
    const _ ultimaduo ← res.take_last(2)
    const _ omissaduo ← res.drop(2)
    const _ inversa ← res.invert()
    const _ ordinata ← [3, 1, 2].sorted()
    print addita
    print sectio
    print primaduo
    print ultimaduo
    print omissaduo
    print inversa
    print ordinata
}

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]

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

Generic ordered collection type.

# =============================================================================
# danh_sách — 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: bảng, tập_hợp, ∷, lặp
# =============================================================================

# danh_sách<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 — danh_sách intrinsic methods not yet lowered for Go
# (whitelist: danh_sách/methodi-mutatio.fab).

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

Expected output:

[1, 2]
3
4

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

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

# =============================================================================
# Exact-bound danh_sách 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
# numeric_lista_operator_law issue. Dynamic `list<T>` operands defer their
# equal-length check to runtime; these literal operands do not.
#
# EXPECTED DECLINE: SEM011:numeric_lista_operator_law
# =============================================================================

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

Expected: compilation rejects this example.