io
The answer word for ok: io.answers.0 when true, else io.answers.1.
Generated from spec/std/io.cp by cpl doc --format json.
Wire
pub struct Wire()Interactive mode. Constructing one (let wire = Wire()) makes every read and the program's
exit flush stdout first; a program that never builds one never flushes early. O(1).
Wire.new
fn new() -> WireA handle that puts the program in interactive mode (spec/core/10-io.md §10.4).
From construction on, every read and every exit flushes stdout first, so a query is never
stuck in the buffer while the program waits for its answer. A program that never constructs a
Wire never flushes early. Constructing a second Wire is allowed and changes nothing.
- cost: O(1)
- traps: never
Examples:
let wire = Wire(); print(1); true
Wire.ask
fn ask<T>(self, query: Str) -> TPrint query and a newline, flush, then read one answer as the T the call site expects.
T comes from the expected type, as with read: fn ask(x: Int, y: Int) -> Int = wire.ask("? {x} {y}"). The answer is read with the same rules as read<T>().
- cost: O(|query|) plus the read of one
T - traps: when input ends before an answer, or the answer is not a valid
T
Examples:
let wire = Wire(); let x: Int = wire.ask("? 1 2"); x == 7(stdin7)
io
pub context ioCompile-time I/O settings: 0/1-based counted domains, field separator, yes words, and float precision.