This library is in flux. APIs may change without notice. Generated from source on 3/14/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 text without newline
~pub event print {
    text: []const u8
}
// Print text with newline
~pub event println {
    text: []const u8
}
// 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 { text: []const u8 }
| eof {}
| failed { message: []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 { line: []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
}
| printed {}
// Success message with green color (if terminal supports it)
~pub event success {
    message: []const u8
}
| printed {}
// Warning message
~pub event warn {
    message: []const u8
}
| printed {}
// ============================================================================
// FILE/STDIN READING - For interpreter and scripting
// ============================================================================
// 
// Read entire stdin as text
~pub event read_stdin {}
| ok { text: []const u8 }
| eof {}
| failed { message: []const u8 }
// Read entire file as text
~pub event read_file {
    path: []const u8
}
| ok { text: []const u8 }
| not_found {}
| failed { message: []const u8 }
// Get command line arguments
~pub event args {}
| ok { argv: []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 { program: *const Program }
~[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 { program: *const Program }
~[norun]pub event print.blk.impl {
    text: []const u8,
}