This library is in flux. APIs may change without notice. Generated from source on 6/15/2026.
I/O
Basic input/output operations for Koru programs
io.kz
Koru Standard Library: I/O
Basic input/output operations for Koru programs
Finally! After achieving consciousness (metacircular compilation),
we can now print "Hello, World!"
// 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 event print {
expr: Expression,
invocation: *const Invocation,
item: *const Item,
program: *const Program,
allocator: std.mem.Allocator
}
| transformed SiteResult// `println` REMOVED — subsumed by `print.ln` (the interpolating print). Calling
// `std/io:println` is now an unknown-event error by design (greenfield: the old
// form must fail loudly once removed).
//
// Print formatted text
// NOTE: printf with varargs would require runtime support - skipping for now
// ~pub event io.printf { format: []const u8, args: anytype }
// | printed {}
//
// ~proc io.printf {
// std.debug.print(format, args);
// return .{ .printed = .{} };
// }
//
// Read line from stdin (for future interactive programs)
~pub event readln {}
| line []const u8
| eof
| failed []const u8// Simple line reader - returns the line, or empty string on EOF/error
// No error handling, just returns what it gets
~pub event read.ln {}
| ok []const u8// Debug print for development
// NOTE: debug with anytype would require runtime support - skipping for now
// ~pub event io.debug { label: []const u8, value: anytype }
// | printed {}
//
// ~proc io.debug {
// std.debug.print("[DEBUG {s}]: ", .{label});
// std.debug.print("{any}\n", .{value});
// return .{ .printed = .{} };
// }
//
// Print error to stderr
~pub event eprintln {
message: []const u8
}// Success message with green color (if terminal supports it)
~pub event success {
message: []const u8
}// Warning message
~pub event warn {
message: []const u8
}// ============================================================================
// FILE/STDIN READING - For interpreter and scripting
// ============================================================================
//
// Read stdin as a stream of lines — the same effect contract as
// std/fs:read-lines, sourced from stdin (the interactive/pipe vertical).
~pub event read-lines {}
| done usize
| failed []const u8// Read entire stdin as text
~pub event read-stdin {}
| ok []const u8
| eof
| failed []const u8// Read entire file as text
~pub event read-file {
path: []const u8
}
| ok []const u8
| not -found
| failed []const u8// Get command line arguments
~pub event args {}
| ok []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 event print.ln {
expr: Expression,
invocation: *const Invocation,
item: *const Item,
program: *const Program,
allocator: std.mem.Allocator
}
| transformed SiteResult~[norun]pub event print.impl {
expr: []const u8,
}// ============================================================================
// 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 event - it's a pure compile-time transformation.
~[comptime|transform]pub event print.blk {
source: Source,
invocation: *const Invocation, // The specific invocation being transformed
item: *const Item,
program: *const Program,
allocator: std.mem.Allocator
}
| transformed SiteResult~[norun]pub event print.blk.impl {
text: []const u8,
}