# raz: standards How raz is written here: in `src/`, `lib/`, `tools/` and `examples/`, and in the programs and libraries that use them (rpg, rsqlite, rmacs, ravite, ...). The report says what a program may do; this says what we do. New code keeps to it; old code comes to it when it is next changed. The library came to it in report 2026-10.33. ## Parameters: a value, `const`, `var`, or a pointer A procedure takes a variable it is given in one of four ways, by what it does with it: | The procedure | The parameter | Example | |---|---|---| | reads it, a single value or a slice | a value | `Sys.write(fd: INT; s: []U8)` | | reads it, a record or an array | `const` | `Map.get(const m: Map; k: K)` | | changes it, and lets go of it when it returns | `var` | `Buf.add(var b: Buf; c: U8)` | | keeps it past the call, in a record, a module variable or another thread | a pointer, `^T` | `Thread.spawn(p, arg: ^U8)` | A `const` parameter is passed in place, as a `var` one is, so nothing is copied; and since it can't be changed, `var` in a heading always means the procedure changes what it is given. A record of only four words passed as a value, copied at each call, made a loop of `Map.get` and `Vec.all` half again as slow as `const` did (2026-10.33). So `ADR` at a call says the callee keeps what it is given. A reader who sees `Pg.start(q, ADR(c), sql)` knows that `q` is changed and `c` is kept, and that `c` must outlive `q`. ``` proc start*(var q: Query; c: ^Conn; sql: []U8); (* q changed; c kept in q *) proc run*(q: Query; var r: Result): ERROR; (* q read; r changed *) proc rows*(r: Result): INT; (* r read: one word *) proc clear*(var r: Result); (* r changed *) ``` A pointer is right also where `var` can't serve: - **An allocator**, `^Mem.Allocator`: `NEW` takes one, and an allocator such as `Arena` is reached through its first field, `^Arena(a)`, which a `var` of exactly one type can't do. - **What may be absent**: a pointer may be `nil`; a `var` can't. - **What the program already holds by pointer**: what `NEW` or the library hands out, such as `Thread.spawn`'s `^Thread`, is passed on as it is, not as `p^`. - **C**, and memory that is bytes, not a variable: `extern` procedures, `Mem.pages`, `Sys.mmap`, a buffer's address. - **A procedure value's argument** that holds what the procedure will need, as `Thread.spawn`'s `arg: ^U8`, which is kept. Anything else that takes `^T` and neither keeps it nor needs one of the above is a mistake, and its callers' `ADR`s are noise. ## A module tests itself A library or support module has its own `proc main*` as its test, and `raztest` runs it. It states what it expects with `Check` (`ok`, `str`, `int`), which reports every failure and ends the run with status 1, and tests a property of its code, one that must hold for any input, with `Prop`, drawing bytes or numbers from its `Source`. A test that passes says nothing. The core modules, and those the compiler imports, keep their own checks, since they can't import a standard-library module. ## A match arm names every field An arm of a `match` on a variant names all of a case's fields, in order, or none. A field the arm doesn't read is named with `_` before its field's name, as in `| real(r, _places):`, so a reader sees it was left unread on purpose and `-Werror` doesn't warn of it.