Operators
Highest precedence first. Every binary operator is left-associative: a - b - c is
(a - b) - c.
| Level | Operators | Meaning | Operand kinds |
|---|---|---|---|
| 1 | ( ) f(…) | grouping, builtin call | |
| 2 | ! - ~ (unary) | logical not, negate, bitwise not | !: any · -: Integer/Real · ~: Integer |
| 3 | * / | multiply, divide | Integer/Real |
| 4 | + - | add or concatenate, subtract | Integer/Real, or Text + Text |
| 5 | << >> | shift left, arithmetic shift right | Integer |
| 6 | < <= > >= | ordering | two numbers, or two Texts |
| 7 | == != | equality | any |
| 8 | & | bitwise AND | Integer |
| 9 | ^ | bitwise XOR | Integer |
| 10 | | | bitwise OR | Integer |
| 11 | && | logical AND (both sides always evaluated) | any (truthiness) |
| 12 | || | logical OR (both sides always evaluated) | any (truthiness) |
There's no modulo (%), exponent operator, ternary (?:) or comma operator.
&& and || don't short-circuit. Both operands are always evaluated, left then right. A builtin
call on the right runs even when the left side already decided the result, and if that call fails,
the action stops. Guard with a nested if instead:
text = ClipboardGetText();
idx = StringGetIndexOf(text, ":");
// WRONG: when idx is -1, StringGetSubstring(text, -1, 5) still runs and stops the action
// if (idx >= 0 && StringGetSubstring(text, idx, 5) == ":here") { ... }
// RIGHT: the second test only runs when the first holds
if (idx >= 0) {
if (StringGetSubstring(text, idx, 5) == ":here") UtilityPrint("found");
}
Bitwise operators bind looser than comparisons (the same as C). flags & 4 == 4 is read as
flags & (4 == 4), which is flags & true, which is 0. Always wrap the mask:
(flags & 4) == 4 or (flags & 4) != 0.
Comparisons don't chain. 0 < x < 10 is read as (0 < x) < 10, which compares a Bool with an
Integer and is always false. Write x > 0 && x < 10.