On this page
Every expression has a checked type. Local binding types are inferred from their initial value unless an explicit let name: Type = value or var name: Type = value annotation is supplied. Word parameter and return annotations are optional when the body and same-program calls determine one concrete type; add annotations when inference is ambiguous. Zhex has no implicit conversions. One exception exists — the string-context Int exception: + concatenates when exactly one operand is Int and the other is String (the Int renders as int.to-string does, chains associate left to right, and two Int operands still add numerically), and print accepts an Int directly. Bool and every other type stay strict in these positions, and no other position converts.
Types
| Type | Values and use |
|---|---|
Int |
Signed 128-bit integers. |
Bool |
true or false. |
String |
Valid UTF-8 text. |
Unit |
The result of statements such as assignment, loops, and print. |
| Temporal values | Date, Time, Duration, Instant, TimeZone, and ZonedDateTime represent distinct calendar and elapsed-time concepts. See dates and time zones. |
Buffer |
A mutable sequence of string lines. See buffers. |
File |
An open file handle. See files. |
| Result values | Input and parsing operations return Result<T, E>; selected collection operations also offer checked forms. User word success types may be inferred from the body or declared with a return annotation; an escaping try makes the checker infer the effective Result signature. Explicit Result<T, E> signatures remain supported, but Results cannot be word parameters, ordinary values, or discarded; handle them immediately with try or catch. User-defined error types are not supported. See results. |
| Records | Nominal named types with typed, immutable fields. They cannot be compared or printed directly. See records. |
| Choices | Nominal named types with a fixed set of alternatives and optional typed payloads; a choice can declare one type parameter. Use exhaustive match to select a case; choices cannot be compared or printed directly. See choices and matching. |
List<T> / Array<T> |
Homogeneous, shared mutable collections. They cannot be compared or printed directly. See lists and arrays. |
Map<K, V> |
Shared mutable key/value collection with insertion-ordered iteration. Keys are String, Int, or Bool; lookup returns built-in Option<V>. Maps cannot be printed or compared directly. See maps. |
Buffer and File are resource values. They are not copied when a name is bound, cannot be compared with == or !=, and are not accepted by print.
The JSON codec supports typed records, lists, string-keyed maps, and Option values in addition to Int, Bool, and String.
Bindings and scope
let creates an immutable binding. var creates a binding that can later be assigned a value of the same type:
let greeting = "Hello"
var count = 0
count = count + 1
print(greeting + " " + int.to-string(count))
Bindings live in lexical block scope. A nested block may shadow an outer name; two bindings with the same name in one scope are an error. Word parameters are immutable. A word does not capture top-level local bindings; pass values through parameters instead.
An if, match, or flow block may supply the entire right-hand side of a let, var, or assignment. See words and flows for a complete example.
Operators
+ adds two integers or concatenates two strings; when exactly one operand is Int and the other is String — the string-context Int exception — the result is String and the Int renders as int.to-string does, with chains associating left to right (1 + 2 still adds numerically). -, *, /, and % operate on integers. Ordering operators require integers. Equality compares matching Int, Bool, or String values. and, or, and not operate on booleans.
let total = 7 + 5
let is-even = total % 2 == 0
if is-even and total > 0
print("positive even total")
The full precedence table is on the syntax page. Binary operators associate left; and and or short-circuit.
Checked arithmetic
Integers are signed 128-bit values (from −170141183460469231731687303715884105728 to 170141183460469231731687303715884105727). Overflow, division by zero, and remainder by zero are runtime errors with source locations. Division truncates toward zero. Remainder has the dividend’s sign. The minimum integer divided by -1 overflows; its remainder modulo -1 is zero. int.mod-floor(value, modulus) is the floored modulo for wrap-around positions: a nonzero result has the modulus’s sign (int.mod-floor(-7, 3) is 2, int.mod-floor(7, -3) is -2), and a zero modulus is the same runtime error as %.
Use int.to-string to format an integer for a string. There is no automatic conversion between numbers and text.
For word signatures and how values move between operations, see words and flows. For branch and loop scope, see control flow.