Types
ROX is a statically typed language. All types must be explicit.
Primitive Types
int64 64-bit Signed Integer
The default integer type. Used for most arithmetic and list indexing.
int64 x = 42;
int64 y = -100;
float64 64-bit Floating Point
Double-precision floating-point number. Used for decimal calculations.
float64 pi = 3.14159;
float64 price = 19.99;
bool Boolean
Values: true or false.
bool is_valid = true;
if (is_valid) { ... }
char Character
Represents a single ASCII character.
char c = 'A';
string String
Immutable sequence of bytes (UTF-8). Literals use double quotes.
string s = "Hello";
int64 len = s.size();
rox_result[char] c = s.at(0);
print(s); // Prints "Hello"
none Unit Type
Represents the absence of a value (similar to void in C++). Used as the return type for functions
that do not return data.
function log() -> none {
print(['H','i','\n']);
return none;
}
Composite Types
list[T] Dynamic Array
Ordered collection of elements of type T.
list[int64] numbers = [1, 2, 3];
rox_result[int64] res = numbers.at(0);
if (isOk(res)) {
int64 first = getValue(res);
}
dictionary[K, V] Hash Map
Key-value pairs. Keys must be comparable (int64, string, bool, char).
dictionary[string, int64] scores;
scores.set("Alice", 100);
rox_result[int64] res = scores.get("Alice");
if (isOk(res)) {
int64 score = getValue(res);
}
Result Type
rox_result[T]
ROX does not use exceptions. Operations that can fail return a rox_result[T].
You must check if the result is valid using isOk() before extracting the value with
getValue().
rox_result[int64] result = list.at(5);
if (isOk(result)) {
int64 val = getValue(result);
} else {
print("Error: ", getError(result), "\n");
}
Use getError(result) to retrieve the error message (string) if isOk() returns false.
Record Types
User-defined types with named, typed fields. Define with the type keyword.
type User {
id: int64
name: string
}
Construction
All fields are required. Use named-field initializers:
User u = User{ id: 7, name: "Taman" };
Field Access & Mutation
print(u.name); // access
u.name = "Apon"; // mutation
Copy Semantics
Assignment copies the entire record. No aliasing.
User b = a; // b is an independent copy
Zero Constructor
default(T) returns the zero/empty value for any type:
User empty = default(User); // id=0, name=""
string s = default(string); // ""
int64 n = default(int64); // 0
list[int64] l = default(list[int64]); // []
Rule: Uninitialized record declarations are banned. User u; is a compile error.
Nested Records
type Address {
city: string
country: string
}
type User {
id: int64
address: Address
}
User u = default(User);
print(u.address.city); // ""
Compile-Time Checks
- Missing required fields
- Unknown field names
- Duplicate fields
- Field type mismatches
- Unknown field access
- Uninitialized record declaration