Operator Reference
Complete operator reference in precedence order (highest to lowest).
Operator Precedence Table
| Precedence | Operators | Description | Associativity |
|---|---|---|---|
| 1 (highest) | () [] . | Grouping, function call, member access, array/tensor indexing | Left-to-right |
| 2 | - ! | Unary negation, logical NOT | Right-to-left (unary prefix) |
| 3 | * / % | Multiplication, division, modulo | Left-to-right |
| 4 | + - | Addition, subtraction, string concatenation | Left-to-right |
| 5 | < <= > >= | Relational comparison | Left-to-right |
| 5 | == != | Equality and inequality | Left-to-right |
| 6 | && | Logical AND | Left-to-right |
| 7 | || | Logical OR | Left-to-right |
| 8 (lowest) | = | Assignment / reassignment | Right-to-left |
Operator Details
1. Grouping, Call, Access () [] .
Associativity: Left-to-right
Parentheses () group sub-expressions. Square brackets [] perform function calls, array indexing, or tensor indexing/slicing. Dot . accesses struct fields, method calls, or module members.
let result = (1 + 2) * 3 // grouping
let val = matrix[0][1] // indexing
let x = point.x // member access
let y = add(3, 4) // function call
let slice = tensor[0:5] // tensor slicing2. Unary - !
Associativity: Right-to-left (prefix unary)
- negates a numeric value (int or float). ! applies logical NOT to a bool.
let neg = -42
let flipped = !true // false
let double_neg = -(-5) // 53. Multiplicative * / %
Associativity: Left-to-right
* multiplies numeric values. / divides numeric values (float division for floats, integer division for ints). % computes the integer modulo.
let product = 5 * 3 // 15
let quotient = 10 / 3 // 3 (integer division)
let float_div = 10.0 / 3.0 // 3.333...
let remainder = 10 % 3 // 14. Additive + -
Associativity: Left-to-right
+ adds numeric values or concatenates strings. - subtracts numeric values.
let sum = 5 + 3 // 8
let diff = 10 - 3 // 7
let greeting = "Hello, " + "World" // string concatenation5. Relational < <= > >=
Associativity: Left-to-right
Compare numeric values. Returns a bool. < less than, <= less than or equal, > greater than, >= greater than or equal.
let a = 5 < 10 // true
let b = 10 <= 5 // false
let c = 8 >= 8 // true5. Equality == !=
Associativity: Left-to-right
== checks value equality (works on all types). != checks value inequality. String comparison is case-sensitive. Struct comparison checks all fields.
let eq = 5 == 5 // true
let neq = "a" != "b" // true
let cmp = nil == nil // true6. Logical AND &&
Associativity: Left-to-right
Short-circuit logical AND. Both operands must be bool. Evaluates right operand only if left operand is true.
let result = (5 > 0) && (10 < 20) // true
let short = false && (risky()) // risky() not called7. Logical OR ||
Associativity: Left-to-right
Short-circuit logical OR. Both operands must be bool. Evaluates right operand only if left operand is false.
let result = (5 < 0) || (10 < 20) // true
let short = true || (risky()) // risky() not called8. Assignment =
Associativity: Right-to-left
Reassigns a value to an existing let-bound variable, a struct field, or an array/tensor element. The left side must be an assignable target. Chaining is supported: a = b = 5 assigns 5 to both.
let x = 0
x = 42 // reassign variable
let rect: Rectangle
rect.width = 100.0 // field assignment
matrix[0][1] = 99 // element assignment
let a = 1
let b = 2
a = b = 10 // both a and b become 10Other Tokens
| Token | Description | Example |
|---|---|---|
| -> | Return type arrow | fn add() -> int |
| => | Match case fat arrow | 1 => print("one") |
| @ | Decorator prefix | @autograd, @layer |
| ... | Ellipsis (tensor all dims) | tensor[..., 0:2] |
| | | Pipe operator | x | f | g |
| : | Type annotation / slicing | x: int, 0:5 |
| ; | Statement terminator | let x = 5; |