aboutsummaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorGravatar zinc <zinc@downsta.ir> 2026-10-15 17:50:10 +0330
committerGravatar zinc <zinc@downsta.ir> 2026-10-15 17:50:10 +0330
commit251b0212f626d0f92eda51906d353712ef4a63b8 (patch)
tree4f0e0b0ee6b0f6d0671261a46bb2bcd15ef0f59c /docs
parentmerge work/actors: wasm seed bootstrap (seed/MANIFEST), shared copy-on-write ... (diff)
parentprescan: guess an owned return only from a local declared from new/heap, not ... (diff)
merge work/demo-fixes: analyzer ownership fixes (back links, loop-built lists, .u inference), Io.print any args, block-end borrow messages
Diffstat (limited to 'docs')
-rw-r--r--docs/LEARN.md2
-rw-r--r--docs/SPEC.md2
2 files changed, 3 insertions, 1 deletions
diff --git a/docs/LEARN.md b/docs/LEARN.md
index eae9ad4..081498d 100644
--- a/docs/LEARN.md
+++ b/docs/LEARN.md
@@ -533,7 +533,7 @@ output:
### 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.
+`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. `print` and `println` take any number of arguments of any printable type, such as `std.Io.println("total: ", n, " avg: ", x);`; the compiler picks the writer for each argument's type (string, byte string, integer or float), and a fresh owned string argument is freed after it is written. `println()` alone writes a line break. other functions have no varargs or overloading. 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):
diff --git a/docs/SPEC.md b/docs/SPEC.md
index 7dd1247..1c65f42 100644
--- a/docs/SPEC.md
+++ b/docs/SPEC.md
@@ -469,6 +469,8 @@ pn((int)(p + 1) - (int)p); // 1: p + 1 moves one word
3.11.6 `heap(e)` copies the value of `e` into a fresh owned heap block sized to it and returns a pointer to the block (a fresh object, 6.1): one word for a scalar or pointer (`heap(10)` is an `int*`), the characters and the terminating 0 for a `char*` word string (`heap("hi")` is a `char*`), and `sizeof(T)` words for a struct or array value (`heap(v)` with `v` a `foo` is a `foo*`). pointer fields of a copied struct are copied as plain words. a struct whose body declares `drop` gives the block its type drop (6.15). `heap` is found only when no variable or function of that name is in scope.
+3.11.7 `std.Io.print(args)` and `std.Io.println(args)` take any number of arguments, including none. each argument is evaluated left to right and written by the writer for its type: a byte string (`bstr`) by `put_bs`, a float by `put_f`, a `char*` or `char[]` by `put_s`, anything else by `put_n`. a fresh owned string argument is written and then freed; another fresh object is error: a new object can't be printed; bind it to a name first. `println` then writes a line break. the call's value is 0. these two are the only calls with a variable number of arguments.
+
### 3.12 `sizeof` and `typeof`
3.12.1 `sizeof(T)` and `sizeof(e)` give the size in words. the expression form is compiled but never run: `int i = 0; int n = sizeof(i++);` leaves `i` 0 and `n` 1. a `u8[100]` is 13 words, a struct of four `u8` fields is 1.