This library is in flux. APIs may change without notice. Generated from source with koruc 0.1.7 on 8/19/2026.
I/O
~import std/ioKoru 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 1 state allocated!// Print without trailing newline — the no-newline sibling of print.ln.
// SAME implementation (__printInterpolate, with_newline=false): comptime
// {{ }} interpolation, rerouted to print.impl for shape checking.
//
// The old RUNTIME passthrough event (`print { text }` + |zig/|js procs) died
// here (2026-06-11, Lars ruling: std/io's print surface is comptime-only;
// stage/runtime printing is the future std/compiler print-family). Its
// positional-arg mis-emit bug died with the codepath.
~[keyword|comptime|transform] pub tor print {
expr: Expression,
invocation: *const Invocation,
item: *const Item,
program: *const Program,
reporter: std/compiler:*ErrorReporter,
allocator: std.mem.Allocator
} -> SiteResultreadln
koru_std/io.kz:66// Read line from stdin (for future interactive programs)
~pub tor readln {}
| line string
| eof
| failed stringread.ln
koru_std/io.kz:79// Simple line reader - returns the line, or empty string on EOF/error
// No error handling, just returns what it gets
~pub tor read.ln {} -> stringeprintln
koru_std/io.kz:105// Print error to stderr
~pub tor eprintln { message: string }success
koru_std/io.kz:116// Success message with green color (if terminal supports it)
~pub tor success { message: string }warn
koru_std/io.kz:123// Warning message
~pub tor warn { message: string }~[
- aspirational
Same gap as std/fs:read-lines: a per-line streaming surface backed by a
whole-stream slurp (readToEndAlloc), bounded by RAM. True streaming is the
deferred honest fix; marked so the gap is explicit and greppable.
]pub tor read-lines {}
! line string
| done usize
| failed string// Read entire stdin as text. The buffer is allocator-owned and carries the
// `allocated!` obligation: hand it to `std/io:free` (auto-discharge inserts
// the call when the trace is unambiguous — most callers never write it).
// Ruled 2026-07-31 (the 335_042/043 question): one label, `allocated`, for
// every allocator-owned buffer an io tor hands back; `std/io:free` is the
// one disposer.
~pub tor read-stdin {}
| ok string<allocated!>
| eof
| failed string// Read entire file as text. `ok` carries the `allocated!` obligation — see
// read-stdin's header; `std/io:free` discharges it.
~pub tor read-file { path: string }
| ok string<allocated!>
| not-found
| failed string// Discharge the `allocated!` obligation on a buffer an io tor handed back
// (read-file, read-stdin). The one disposer for the one label.
~pub tor free { content: string<!allocated> }args
koru_std/io.kz:236// Get command line arguments
~pub tor args {} -> []const []const u8// PRINT.LN - Interpolated printing with Expression (ZERO OVERHEAD)
//
// Syntax: std/io:print.ln("Hello {{ name }}! Count: {{ count }}")
//
// ARCHITECTURE:
// - print.ln is a comptime transform that generates inline Zig code
// - Parses {{ ... }} placeholders from the Expression string
// - Optional format specifier: {{ name:s }} or {{ count:d }}
// - Generates: std.debug.print("Hello {}! Count: {}\n", .{name, count});
//
// This is NOT a regular event - it's a pure compile-time transformation.
~[keyword|comptime|transform] pub tor print.ln {
expr: Expression,
invocation: *const Invocation,
item: *const Item,
program: *const Program,
reporter: std/compiler:*ErrorReporter,
allocator: std.mem.Allocator
} -> SiteResult~[norun] pub tor print.impl { expr: string }// eprint / eprint.ln — the stderr siblings of print / print.ln. Same engine
// (__printInterpolate), routed to fd 2. They reuse print.impl for shape
// checking (the reroute is analysis-only; the inline body does the write).
~[keyword|comptime|transform] pub tor eprint.ln {
expr: Expression,
invocation: *const Invocation,
item: *const Item,
program: *const Program,
reporter: std/compiler:*ErrorReporter,
allocator: std.mem.Allocator
} -> SiteResult~[keyword|comptime|transform] pub tor eprint {
expr: Expression,
invocation: *const Invocation,
item: *const Item,
program: *const Program,
reporter: std/compiler:*ErrorReporter,
allocator: std.mem.Allocator
} -> SiteResult~[comptime|transform] pub tor print.blk {
source: Source,
invocation: *const Invocation,
item: *const Item,
program: *const Program,
reporter: std/compiler:*ErrorReporter,
allocator: std.mem.Allocator
} -> SiteResult~[norun] pub tor print.blk.impl { text: string }