This library is in flux. APIs may change without notice. Generated from source with koruc 0.1.7 on 8/19/2026.
Constructor
~import std/constructorKoru Standard Library: Constructor — the comptime assembly sandwich.
constructor.kz · 4 tors · ~[comptime]
Koru Standard Library: Constructor — the comptime assembly sandwich. · 15 more lines
Koru Standard Library: Constructor — the comptime assembly sandwich.
The constructor is `capture` generalized from a scalar cell to a GROWING
structure. Where `capture` folds one cell (`! as` / `captured` / `| captured`),
the constructor COLLECTS (`! construct` / `push` / `| constructed`). The whole
thing is comptime and DISSOLVES — allocations happen at comptime and never
reach the binary. Runtime collection is not the constructor; it's the store.
SURFACE: `std/constructor(nums)` invokes the module's `default` event (the
default-event rule: `std/M(args)` ≡ `std/M:default(args)`). The header arg is
the cell NAME; the `! construct` half drives a LINQ traversal whose `push`
calls collect into the cell; `| constructed <r>` is the one-shot after-read.
This file currently builds the VALUE terminal (a comptime list). The struct /
type terminals (the `field` vocabulary + `std/types:emit`) follow.
// The module's DEFAULT event — reached bare as `std/constructor(nums)`. Not a
// keyword (keyword elides the module path; default IS the module path). `expr` is
// the first-parameter implicit slot: `std/constructor(nums)` lands `expr = "nums"`.
//
// `pre` stage: the constructor must DISSOLVE before the elaboration template pass
// runs, so its grafted `for(built)` (over the comptime list it defines) is
// template-processed as ordinary code. The pipeline runs `.pre` transforms via
// `run-pre-transforms`, ahead of `process-template-procs` (see compiler.kz).
~[comptime|transform|pre] pub tor default {
expr: Expression,
reporter: std/compiler:*ErrorReporter
}
! construct *
| ?constructed *// The core collect verb, consumed by the transform (never emitted). `expr` is the
// implicit first slot so `push(x)` needs no label.
~pub tor push { expr: Expression }// STRUCT KIND terminal — `std/constructor:struct(Vec3)` GENERATES a struct type
// from field specs collected over a LINQ range. GENERATION only: no existing type
// is read, so no registry — the lowered `@Type` lives in Zig's own scope. `.pre`
// keeps it consistent with the value terminal (dissolves before the main passes).
~[comptime|transform|pre] pub tor struct {
expr: Expression,
reporter: std/compiler:*ErrorReporter
}
! construct *// The field vocabulary verb (consumed by the struct transform). `name` is a
// projection template (`"v{i}"` splices the loop var); `type` is the field type.
~pub tor field { name: Expression, type: Expression }