This library is in flux. APIs may change without notice. Generated from source with koruc 0.1.7 on 8/19/2026.
Control
~import std/controlKoru Standard Library: Control Flow
control.kz · 4 tors · ~[comptime]
Koru Standard Library: Control Flow
Provides if for zero-overhead conditional branching
ARCHITECTURE: if is a pure comptime transform that generates inline Zig code.
- if(expr) | then |> ... | else |> ... becomes a literal if/else statement
- No function call overhead, full access to outer scope
- Uses template_utils.lookupTemplate + interpolate for metaprogramming!
~[keyword] pub tor if { expr: Expression }
| ?then
| ?else~[keyword] pub tor cond { expr: Expression }
| c *// - `keep:` is OPTIONAL and turns the loop into one that STOPS: the emitted body
// breaks the moment the expression goes false. Omit it and `for` is exactly
// what it always was — an absent `keep` renders no line at all, so every
// existing call site emits byte-identical code.
//
// This started life as a separate `scan` keyword and that was WRONG. The two
// templates differed by ONE line and shared everything else, across two targets
// — four procs where two do. That is the two-lowerings-of-one-construct shape
// this repo keeps getting bitten by (`frag-a-fix-lands-in-one-lowering-path`),
// installed deliberately by someone who had written that concept's newest
// section the same morning. A second copy that merely agrees today is the same
// bug waiting: the next person to improve the JS range handling would have had
// to remember there were two homes for it. Lars caught it; converging is the
// concept's own prescription.
~[keyword] pub tor for { expr: Expression, keep: ?Expression }
! each *
| ?done~[keyword|comptime|transform] pub tor capture {
source: Source,
reporter: std/compiler:*ErrorReporter
}
! as *
| ?captured *