Types
VDX supports four value types: int, float, string, and bool. You can optionally annotate variables with a type for runtime checking.
Value types
| Type | Example | Description |
|---|---|---|
int | 42 | Whole numbers |
float | 3.14 | Decimal numbers |
string | "hello" | Text |
bool | true / false | Boolean values |
Number literals
Any number with a decimal point or exponent is a float. v0.1.5+ also supports hex ints and compact float forms:
let pi = 3.14;
let half = 0.5;
let five = 5.0; // float, not int
let big = 1e5; // 100000.0 — exponent (v0.1.5+)
let small = 1.5e-3; // 0.0015 (v0.1.5+)
let one = 1.; // 1.0 — trailing dot (v0.1.5+)
let frac = .5; // 0.5 — leading dot (v0.1.5+)
let hex = 0xFF; // 255 — hex int (v0.1.5+)
print(pi); // 3.14Boolean literals
Use true and false directly:
let active = true;
let done = false;
if (active) {
print("active!");
}Type annotations
Add a type after the variable name with : to enable runtime type checking:
let count: int = 42;
let pi: float = 3.14;
let name: string = "VDX";
let ok: bool = true;Type annotations are optional. Without them, variables accept any value. Container annotations work too: let nums: int[] = [1, 2]; and let u: dict = {"k": 1}; (v0.1.5+ — int[] actually parses now).
Type mismatch errors
If the value doesn't match the annotation, VDX throws a runtime error:
let x: int = "hello";
// error: Type mismatch: expected 'int', got 'string'The float annotation accepts both float and int values (widening).
Mixed arithmetic
When an int and float are used together in an operation, the result is automatically promoted to float:
print(10 + 3.5); // 13.5
print(2 * 3.14); // 6.28
print(7 / 2.0); // 3.5Truthiness
| Type | Truthy | Falsy |
|---|---|---|
| int | != 0 | 0 |
| float | != 0.0 | 0.0 |
| string | non-empty | "" |
| bool | true | false |
| array | non-empty | [] |
| object | always | — |
| void | — | always |