Operators from highest to lowest priority
Parenthesis( )Groups expressions:
(1 + 2) * 3; or creates tensors: pair = (1, 2).
Square brackets [ ]Creates typed tuples:
[1, 2].
Operator lazySee lazy loading. Non-null assertion operator
!Skips the nullability check:
someVar!. See nullable types.
Unary operators ! ~ - +Logical negation
!x (see booleans), bitwise not ~x, unary -x and +x.
Operators as is !isUnsafe
as cast and check a union type: someVar is int.
Multiplicative * / % ^/ ~/Integer multiplication, division, modulo, ceiling-division, and rounding-division. Note that all integers have 257-bit precision. Additive
+ -Standard integer addition and subtraction. Shifts
<< >> ^>> ~>>Bitwise shifts, extended by ceiling-right and rounding-right. Comparison
== < > <= >= != <=>Comparison operators. The last one is known as the “spaceship” or “sign” operator. Operators
== and != work also for several non-numeric types (particularly, addresses).
Bitwise & | ^Standard bitwise operators, applicable to both integers and booleans. Logical
&& ||Short-circuit: the right operand is evaluated only when necessary. Assignment
= += -= and otherAssignment and augmented assignments. Ternary
... ? ... : ...See conditions and loops.
Missing operators
Tolk does not havei++ and i--. Use i += 1 and i -= 1 instead.
Warnings on potentially unexpected precedence
A common pitfall across many languages:flags & (0xFF != 0),
because != has higher priority (the same in C++ and other languages).
To prevent such problematic cases, the compiler triggers an error: