Skip to content

Syntax & Variables

Tulpar supports the following data types:

TypeDescriptionExample
intInteger numbersint x = 42;
floatFloating-point numbersfloat pi = 3.14;
strUTF-8 stringsstr name = "Hamza";
boolBoolean valuesbool flag = true;
arrayMixed-type arraysarray mix = [1, "text", 3.14];
arrayIntType-safe integer arraysarrayInt nums = [1, 2, 3];
arrayFloatType-safe float arraysarrayFloat vals = [1.5, 2.5];
arrayStrType-safe string arraysarrayStr names = ["Ada", "Linus"];
arrayBoolType-safe boolean arraysarrayBool flags = [true, false];
arrayJsonJSON-like objectsarrayJson obj = {"key": "value"};

Variables are declared with their type:

Variables

Integers can be written in four bases. Underscores are not allowed — keep large numbers readable with comments instead.

FormExampleDecimal value
Decimal255255
Hexadecimal0xFF255
Octal0o755493
Binary0b101010

Floating-point numbers accept the standard C-style forms:

float pi = 3.14;
float small = 1.0e-5;
float large = 6.02e23;

Integers above i64 range trigger a compile-time warning and are clamped to INT64_MAX (2^63 − 1).

Strings are UTF-8 and concatenate with +. When either side of + is a string, the other operand is coerced to its text form automatically — "count: " + 5 is "count: 5", no toString() needed.

For readable interpolation, use a t-string — prefix a string literal with t and embed expressions in { }:

str name = "Hamza";
int age = 24;
// t-string: expressions in { } are evaluated and stitched in.
print(t"{name} is {age} years old");
// Any expression works inside the braces.
int a = 3; int b = 4;
print(t"sum = {a + b}, bigger = {a > b}");
// Index access (inner quotes are fine):
json user = {"name": "Ada", "role": "admin"};
print(t"user {user["name"]} ({user["role"]})");
// A literal brace is written \{ ... \}
print(t"\{not interpolated\} but {age} is");

A t-string always produces a str, even when it is only an interpolation (t"{n}"). Write a literal brace as \{ / \}. The plain + concatenation is still available when you prefer it.

Operators are listed from lowest to highest precedence. Operators on the same row have equal precedence and associate left-to-right unless noted.

TierOperatorsAssociativity
1 (lowest)= += -= *= /=right
2||left
3&&left
4== !=left
5< > <= >=left
6+ - (binary)left
7* / %left
8- (unary), !right
9 (highest)++ -- (postfix), () call, [] index, . memberleft

Use parentheses when in doubt — they read better than relying on precedence rules across more than one tier:

// Both compile, but the parenthesised form is clearer.
int score = a + b * c; // = a + (b * c)
int score = a + (b * c);

Tulpar supports single-line and multi-line comments:

Comments