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

I/O

import std/io

Koru Standard Library: I/O

io.kz · 17 tors · ~[comptime]· ~[runtime]

Koru Standard Library: I/O Basic input/output operations for Koru programs Finally! After achieving consciousness (metacircular compilation), we can now print "Hello, World!"

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.

string 2 states allocated!

print

keywordcomptimetransform koru_std/io.kz:26

eprintln

<*@scoped> koru_std/io.kz:102

success

<*@scoped> koru_std/io.kz:113

warn

<*@scoped> koru_std/io.kz:120

read-lines

aspirational koru_std/io.kz:137

read-stdin

<allocated!> koru_std/io.kz:173

read-file

<allocated!> koru_std/io.kz:197

free

<!allocated> koru_std/io.kz:225

print.ln

keywordcomptimetransform koru_std/io.kz:262

print.impl

norun <*@scoped> koru_std/io.kz:271

eprint.ln

keywordcomptimetransform koru_std/io.kz:278

eprint

keywordcomptimetransform koru_std/io.kz:287

~part jsprec koru_std/io.jsprec.kz

Koru Standard Library: I/O — JS placeholder operand emission. Joined via `~part jsprec` in io.kz; merged into the io module at load. Emit one `{{ … }}` placeholder's VALUE operand for the JS concat `__printInterpolateJs` is building. The raw text between the braces arrives untrimmed; the spec after the first `:` is dropped — JS `+` promotes Numbers to strings on concat, so no per-spec mapping is needed — EXCEPT a `:.N` precision tail, which emits `Number(x).toFixed(N)`, the same honoring fmt's jsPlaceholder gives `ln|js` (same parse as it). A lone/leading operand is parenthesized so a multi-term expr (`{{ c + 1 }}`) is ONE operand — `"n=" + c + 1` would otherwise fold left-to-right to `"n=<c>" + 1` = "n=<c>1" instead of the sum.

~part csprec koru_std/io.csprec.kz

Koru Standard Library: I/O — CS placeholder operand + interpolation engine. Joined via `~part csprec` in io.kz; merged into the io module at load. The K# vertical's print path. Same surface as __printInterpolateJs — string-literal vs bare expression, `{{ var:fmt }}` placeholders, `{% if v %}…{% endif %}` blocks — and nearly the same emitted text: `"" + x + "lit"` is valid C# (string concat promotes the operand exactly like JS), and `(cond ? "body" : "")` is the same ternary. What differs lives in the two helpers here: exprs lower through the `.cs` arm (and/or, .len, `++`, reserved words) and a `:.N` precision tail honors via `.ToString("F"+N, InvariantCulture)` rather than JS's toFixed — C#'s culture-sensitive formatting would otherwise answer "3,14" for "3.14" in half the world's locales. CS-target interpolation engine — the __printInterpolateJs twin. SAME expr surface, same reroute-to-print.impl surgery; only the emitted operand text differs, and both helpers producing it live above.

~part lowers koru_std/io.lowers.kz

Koru Standard Library: the `lowers` part of io.kz. Joined via `~part lowers` in io.kz; merged into the io module at load. The `{{ … }}` interpolation doors — one per host vocabulary arm. Both engines splice a Koru expression into host text through these twins; they live together because a fix to the lowering contract lands in both places or in neither. A `{{ … }}` INTERPOLATION IS A KORU EXPRESSION, and this builder splices it into JavaScript. It is the third door onto the same pass — after `std/store`'s guards and `std/kernel`'s op bodies — and it was the last one still writing the text through raw. What that cost: `print.ln("… {{ new:s }}")` over `! updated { old, new }` emitted a bare `new` into the concatenation, and node refused the file. It also meant an interpolation naming `a and b` or `@as(i64, x)` reached node unlowered, which nothing had noticed because no test interpolates one. Refusal is swallowed rather than reported: an unmodelled `@`-operation here falls back to the raw text, which is what this site did for every expression until now, so the failure mode is unchanged rather than newly silent. The diagnostic belongs with the print transform's own error surface and that is a separate job.

~part blkcs koru_std/io.blkcs.kz

Koru Standard Library: the `blkcs` part of io.kz. Joined via `~part blkcs` in io.kz; merged into the io module at load. print.blk|cs — the C#-target variant of the block-print transform, ported from print.blk|js in io.blk.kz. Same scan: `{% if v %}…{% endif %}` → `(v ? "escaped" : "")` (C#'s ternary is the same shape), `{{ var:fmt }}` → the ioCsPlaceholderOperand door (parens + .cs lowering + the :.N honoring), literal runs escaped into `"…"` segments, all joined by ` + ` — C# string concat promotes the operand exactly like JS. Newline: JS's console.log appends one, so |js strips a trailing `\n` from the template content. __koru_stdout_write is a bare Write — the same strip applies, then the newline is re-added inside the concat, so the emitted program writes exactly what |zig's raw_posix writes.

~part blk koru_std/io.blk.kz

Koru Standard Library: I/O — the `print.blk` family. Joined via `~part blk` in io.kz; merged into the io module at load. Lifted out of io.kz so both files stay under their line baselines; module-scope names (KORU_OUT_FN, __appendFmtLiteralByte, codegen_utils_io, the expr_parser idiom) resolve through the merge. PRINT.BLK - Multi-line block printing with Source block (ZERO OVERHEAD) Syntax: std/io:print.blk { Header: {{ title }} Value: {{ count }} } ARCHITECTURE: - Takes a Source block (multi-line text) - Parses {{ ... }} and {% if %} placeholders - Generates inline Zig print statement This is NOT a regular tor - it's a pure compile-time transformation.

print.blk

comptimetransform koru_std/io.blk.kz:23

print.blk.impl

norun koru_std/io.blk.kz:32