Operators & Precedence
Arithmetic, exponentiation, comparison, short-circuiting logical operators, and indexing/slicing.
Operator Precedence
Ordered from highest (tightest binding) to lowest:
| Operators | Description | Associativity |
|---|---|---|
f(...), x[i], x[a:b], x.field | Call, index, slice, field access | Left |
^ | Exponentiation | Right |
+x, -x | Unary positive / negation | Prefix |
*, /, % | Multiplication, division, remainder | Left |
+, - | Addition / string concatenation, subtraction | Left |
==, !=, <, <=, >, >= | Value comparison | Left |
not | Logical negation | Prefix |
and | Short-circuiting logical AND | Left |
or | Short-circuiting logical OR | Left |
Indexing & Slicing
Lists and strings support 0-based indexing and half-open [start:stop] slices:
ops.dl
nums = [10, 20, 30, 40]
show nums[0] # 10
show nums[1:3] # [20, 30]
show 2 ^ 3 ^ 2 # 512 (right-associative)
show "hi " + "there"