Operators

VDX supports arithmetic, comparison, and equality operators.

Arithmetic

OperatorDescriptionExample
+Addition3 + 2 → 5
-Subtraction10 - 4 → 6
*Multiplication3 * 4 → 12
/Division (integer)7 / 2 → 3
%Modulo (remainder)7 % 3 → 1
-xUnary minus-5 → -5

Comparison

OperatorDescriptionExample
<Less than3 < 5 → true
>Greater than5 > 3 → true
<=Less or equal3 <= 3 → true
>=Greater or equal5 >= 3 → true

Equality

OperatorDescriptionExample
==Equal5 == 5 → true
!=Not equal5 != 3 → true

String concatenation

The + operator also concatenates strings:

let greeting = "Hello" + " " + "world";
print(greeting);    // Hello world

Comparison operators work on strings too (v0.1.5+) — lexicographic order: "apple" < "banana" → true

Logical (v0.1.5+)

OperatorDescriptionExample
!Logical not (truthiness)!done
&&Logical and — short-circuitsx > 0 && y > 0
||Logical or — short-circuitsa || 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:

  1. ! -x ++ -- — unary
  2. * / % — multiplication, division, modulo
  3. + - — addition, subtraction
  4. < > <= >= — comparison
  5. == != — equality
  6. && — logical and (v0.1.5+)
  7. || — logical or (v0.1.5+)

Use parentheses () to override precedence.

Division by zero

Dividing by zero throws a runtime error:

[VDX] Division by zero