This library is in flux. APIs may change without notice. Generated from source with koruc 0.1.7 on 8/19/2026.

Declarations

~import std/declarations

Koru Standard Library: Declarations

declarations.kz · 1 tors · ~[comptime]

Koru Standard Library: Declarations · 36 more lines
Koru Standard Library: Declarations Name-introducing constructs that are neither control flow nor type declarations. Today this is `const` — a module-level VALUE binding. It used to live in `control.kz`, but a value declaration is not control flow; and it is not a type, so it does not belong in `types.kz` either. It is its own thing: a declaration. This module is auto-imported via `index.kz` (like `control`), so the `const` keyword is globally available whenever any std/* module is imported. CONST - module-level value declarations as a per-target TEMPLATE. const({ threshold: 5 }) | as cfg |> ...use cfg.threshold... Much simpler than capture: - No mutation, so no `captured` branches to transform - No runtime struct type conversion needed - Just binds constants and flows through Syntax: const { name: "Claude", count: 42 } (newline- OR comma-separated) ARCHITECTURE: `const` is a `[template]` proc over a `source: Source` block — NOT a transform. The block is captured WHOLE as a Source (no first-field truncation), and the `parse_fields` Zig FILTER (template_processor.zig) splits it into `{ name, value }` records. Both the |zig| and |js| variants call that SAME filter, so the two lowerings of a const block cannot drift. Each field becomes a `const name = value;` declaration; values are emitted verbatim, and per-target value shaping (a future `comptime_int` vs `number` split) rides the variant boundary — exactly like `if`/`for`. This replaces the old transform-+-codegen_utils.koruStructToConstDecls path ("emit Zig and hope"). `[declaration]`: this keyword template emits DECLARATIONS (names into the enclosing scope), not a statement. The emitter splices a declaration flow's rendered body directly at container scope (struct members), NOT wrapped in a `flow()` function — so sibling flows see the names via Zig container-scope lookup. Contrast `if`/`for`, which emit statements into a function body.

const

keyworddeclaration koru_std/declarations.kz:41