Operators
VDX supports arithmetic, comparison, and equality operators.
Arithmetic
| Operator | Description | Example |
|---|---|---|
+ | Addition | 3 + 2 → 5 |
- | Subtraction | 10 - 4 → 6 |
* | Multiplication | 3 * 4 → 12 |
/ | Division (integer) | 7 / 2 → 3 |
% | Modulo (remainder) | 7 % 3 → 1 |
-x | Unary minus | -5 → -5 |
Comparison
| Operator | Description | Example |
|---|---|---|
< | Less than | 3 < 5 → true |
> | Greater than | 5 > 3 → true |
<= | Less or equal | 3 <= 3 → true |
>= | Greater or equal | 5 >= 3 → true |
Equality
| Operator | Description | Example |
|---|---|---|
== | Equal | 5 == 5 → true |
!= | Not equal | 5 != 3 → true |
String concatenation
The + operator also concatenates strings:
let greeting = "Hello" + " " + "world";
print(greeting); // Hello worldComparison operators work on strings too (v0.1.5+) — lexicographic order: "apple" < "banana" → true
Logical (v0.1.5+)
| Operator | Description | Example |
|---|---|---|
! | Logical not (truthiness) | !done |
&& | Logical and — short-circuits | x > 0 && y > 0 |
|| | Logical or — short-circuits | a || b |
&& and || short-circuit: the right side is not evaluated when the result is already decided. Operands use normal truthiness rules (0, 0.0, "", [] are falsy).
Precedence
From highest to lowest:
!-x++--— unary*/%— multiplication, division, modulo+-— addition, subtraction<><=>=— comparison==!=— equality&&— logical and (v0.1.5+)||— logical or (v0.1.5+)
Use parentheses () to override precedence.
Division by zero
Dividing by zero throws a runtime error:
[VDX] Division by zero