aboutsummaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorGravatar zinc <zinc@downsta.ir> 2026-10-15 09:42:25 +0330
committerGravatar zinc <zinc@downsta.ir> 2026-10-15 09:42:25 +0330
commitde4da84ca3159ad0ebcf13729716be5f4d7bbc2a (patch)
tree216f00007206fdc15dccd3327884b4c0dad94446 /docs
parentxref: baseline records the prover's writers of ft_ln (bin, kw_for), xub and x... (diff)
std: add std.Io (print, println, nl, put_*, put_f, get_c, eof, read, getline) with test, learn example and docs
Diffstat (limited to 'docs')
-rw-r--r--docs/LEARN.md24
1 files changed, 24 insertions, 0 deletions
diff --git a/docs/LEARN.md b/docs/LEARN.md
index ed12caf..35ee914 100644
--- a/docs/LEARN.md
+++ b/docs/LEARN.md
@@ -531,6 +531,30 @@ output:
124
```
+### terminal input and output
+
+`std.Io` groups the terminal: `print(s)` and `println(s)` write a string, `nl()` a line break, and `put_c`, `put_s`, `put_n`, `put_hex`, `put_bs` and `put_f` write a character, a string, a decimal or hexadecimal integer, a packed byte string and a float. `get_c()`, `eof()`, `read(buf, n)` and `getline(buf, n)` read the program input; `getline` drops the line break and returns -1 at the end of the input. zc has no varargs or overloading, so `print` takes a string only and numbers use their own writers. the writers go through `rt.put_c`, so `std.capture` sees them, and the `rt` names (`rt.put_n` and the rest) keep working.
+
+[example source](../examples/learn/35-io.zc):
+
+```zc
+namespace;
+include std;
+fn main() {
+ std.Io.print("total: "); std.Io.put_n(6 * 7); std.Io.nl();
+ std.Io.print("ratio: "); std.Io.put_f(1.0 / 4.0); std.Io.nl();
+ std.Io.println("done");
+}
+```
+
+output:
+
+```text
+total: 42
+ratio: 0.250000
+done
+```
+
### host services
`rt.syscall(op, a, b, c)` calls the runtime interface to the vm's syscall gate. the runtime defines names such as `SYS_OPEN`, `SYS_READ`, `SYS_WRITE`, `SYS_GETENV`, and `SYS_TIME`. unsupported operations return -1. `std.Host.now()` wraps the clock request.