This library is in flux. APIs may change without notice. Generated from source with koruc 0.1.7 on 8/19/2026.
List
~import std/liststd/list — growable list with an active/free ownership model.
list.kz · 7 tors
std/list — growable list with an active/free ownership model.
First cut: monomorphized by hand for i64 (the trunk type). This mirrors
string.kz's String/u8: an owned handle carrying its allocator, with phantom
obligations on the ownership state. Genericity over element types (the
container-generating [transform] from the collections design) lands later by
replication; the obligation/phantom model proven here is the same for every T.
Ownership states (phantom on *List_i64):
<list!> - new issues the obligation: this list must be freed (or drained).
<list> - borrowed: read/mutate in place (push, len), obligation untouched.
<!list> - consumed: free discharges the obligation.
Phantom lifecycles
Derived from the phantom labels in the declarations below — state! issues an
obligation the compiler will chase, !state discharges it, a bare state holds it without moving it. Nothing here is hand-drawn.
List_i64 1 state list!// Construction
//
// Generic constructor. `new(i64)` reads the element-type expression at comptime
// and rewrites its call site to the concrete `new-<type>` runtime constructor
// (e.g. `new-i64`). This is generic-by-name: when `new-f64` exists, `new(f64)`
// routes to it automatically. A type expression is inherently comptime, so this
// must be a [transform] — a plain event taking the type as an Expression would
// make the whole flow comptime. The branches (`| list` / `| err`) carry over to
// the concrete constructor unchanged.
~[comptime|transform] pub tor new {
expr: Expression,
invocation: *const Invocation,
item: *const Item,
allocator: std.mem.Allocator
} -> SiteResult// Concrete i64 constructor (runtime). `new(i64)` rewrites to this. Carries the
// <list!> ownership obligation.
~pub tor new-i64 {}
| list *List_i64<list!>
| err string// Mutation (borrow — obligation untouched)
//
// Append a value. Void, chains with `|>`. OOM panics (the approved split: a
// growable push is loud-on-failure, not a per-call error branch).
~pub tor push { xs: *List_i64<list>, v: i64 }// Read (borrow)
//
// Current length as a scalar. (The `xs.len` expression form rides a separate
// bridge; this event is the plain call form.)
~pub tor len { xs: *List_i64<list> } -> usize// Random access by index. <list> borrow — read, list untouched. `out-of-bounds`
// when i is past the end.
~pub tor get { xs: *List_i64<list>, i: usize }
| item i64
| out-of-bounds// Remove and return the last element. <list> borrow: the list stays alive (the
// binding keeps <list!>), so it can be popped again or freed. `empty` when there
// is nothing to pop. For i64 the popped value carries no obligation; an element
// type that DID would have its obligation reissued to `v` here.
~pub tor pop { xs: *List_i64<list> }
| item i64
| empty// Teardown (consume — discharges <!list>)
~pub tor free { xs: *List_i64<!list> }