Language reference
Language reference
Find the rules for values, functions, types and execution.
Use this reference when you know what you want to write and need its syntax or behavior. For a guided introduction, start with the tutorial. The function library has a separate alphabetical index.
Values and types
Numeric types are int8, int16, int32, int64, uint8, uint16, uint32, uint64, float32 and float64. The aliases int, uint and float mean their 64-bit counterparts on every target. Bool has the values true and false; String holds UTF-8 text. Arrays use [T]; numerical tensors use Tensor[T, dimensions]. A scalar and a rank-zero tensor are different types. Define domain-specific values with records and enums.
- Lexical structure, bindings and expressions
- Numeric types and arithmetic
- String literals and Unicode indexing
- Array values
- Tensor types, shapes and indexing
- Record and enum declarations
Mutation at a glance
Reassignment changes a local binding; an element write changes array storage. These are different operations.
| Operation | Rule |
|---|---|
| Reassign a numeric or Bool scalar | Allowed locally; the type stays fixed |
| Replace a numeric or Bool CPU array binding | Allowed; existing aliases retain the previous array |
| Write a numeric or Bool array element | Requires writable storage and no unfinished task readers |
| Write through an array parameter | The parameter must declare mut |
| Edit a String or tensor in place | Not supported; construct a new value |
| Update a record | Use with to construct a new record |
Functions and control flow
Functions return their final expression. A function value can be passed to another function or retain values from its defining scope as a closure. if chooses a branch, while repeats a body, for visits array elements or integer ranges, and match selects a declared enum or error alternative. Conditions and loops support both statement and expression forms; break and continue control the nearest loop. Function signatures record parameter access and any expected-error channel.
- Definitions, function values, closures and recursion
- Conditions, loops, exits and pattern matching
- Error declarations, try, fail and catch
- Imports, exports and re-exports
Tasks and placement
spawn, await, parallel, try and on are language constructs, not ordinary functions. A parallel scope owns its children and settles them before leaving. Device selectors and transfer are documented separately as callable built-ins. A tensor result awaited from a GPU task remains resident until an explicit transfer changes its placement.
Operators and evaluation
Numeric expressions use +, -, *, / and integer remainder %. String concatenation uses +. Comparison operators are ==, !=, <, <=, > and >=; their accepted operands must have compatible types. Bool expressions use not, and and or. Conditions and Boolean and/or use lazy selection, so an unselected expression does not run. Comparison chaining requires explicit grouping rather than Python-style chained comparisons.
Multiplication, division and remainder bind more tightly than addition and subtraction. The -> pipeline passes its left expression as the first argument of the call on its right. Use parentheses to make the intended grouping explicit, especially when combining a pipeline with arithmetic or comparisons.
Indexes are zero-based. Array and String indexing uses one index; tensor indexing uses one per dimension. Bounds are checked. An indexed expression reads a value. Numeric and Bool CPU arrays also permit checked element assignment when the caller has write access and no unfinished task readers share that storage. Strings and tensors do not support in-place edits.