Words let you define custom operators from identifiers. Each word has a fixed position — prefix, infix, or suffix — with language-defined precedence.
use, even if you already imported its module.context (§17).| Type | Description | Example |
|---|---|---|
operator |
Overload a specific operator (+, -, *, (), etc.) |
implement Vec3 as Arithmetic { fn +(self, other: Self): Self { ... } } |
token |
A word with low precedence that does nothing alone. Serves as a named argument for macros and other words. | token SELECT; |
Operator words overload built-in operators. Use implement with a capability to define the behavior:
implement Vec3 as Arithmetic {
fn +(self, other: Self): Self { ... }
fn -(self, other: Self): Self { ... }
fn *(self, scalar: f32): Self { ... }
}
// Custom word — not overloading a built-in operator
use math.vec.dot as DOT;
use math.vec.cross as CROSS;
// Infix — reads as dot(vec1, vec2)
let d = vec1 DOT vec2;
// Prefix — reads as VALIDATE input
let result = VALIDATE data;
// Suffix — reads as input CHECK
let value = input CHECK;
| Position | Reads as |
|---|---|
| Infix | a DOT b → dot(a, b) |
| Prefix | not x → not(x) |
| Suffix | x! → assert(x) |
Token words have low precedence and do nothing alone. They serve as named arguments for macros and other words — e.g., SQL keywords:
token SELECT;
token FROM;
token WHERE;
// Operator* defines behavior for a token
operator* (SELECT, list) { ... }
Tokens are useful for DSLs where keywords need to be passed as arguments without function call syntax.
() syntax, can't return values.Words let you pass keywords, words, and macros as arguments.
Zith Language Specification — Draft v0.9