Variables and Types
RUDRA is statically typed. Bindings are immutable by default.
Bindings
Use let for an immutable binding and let mut for a mutable one.
fn main() -> int {
let name = "RUDRA";
let mut count = 3;
count = count + 1;
print(name + "\n");
print(to_str(count) + "\n");
return 0;
}
return main(); Type annotations
You can annotate a binding with its type. print accepts only a str and adds no newline, so convert numbers with to_str.
fn main() -> int {
let title: str = "Systems language";
let answer: int = 42;
let ratio: float = 3.5;
let ok: bool = true;
print(title + "\n");
print(to_str(answer) + "\n");
if ok {
print("ok\n");
}
return 0;
}
return main(); Core types
| Type | Description | Example |
|---|---|---|
int | Integer | 42 |
float | Floating-point number | 3.14 |
bool | Boolean | true, false |
str | String | "text" |
Lists
RUDRA has no fixed-size array literals. Use list[int]: create it with list_new(), add with push, read with get (indexed from zero) and count with list_len. Lists are capped at 512 elements, and an out-of-range access aborts the program (exit 134).
fn main() -> int {
let nums = list_new();
push(nums, 10);
push(nums, 20);
push(nums, 30);
print(to_str(get(nums, 0)) + "\n");
print(to_str(get(nums, 2)) + "\n");
print(to_str(list_len(nums)) + "\n");
return 0;
}
return main(); Strings
Strings concatenate with +; str_len returns a string length and substr(s, start, length) extracts part of a string.
fn main() -> int {
let greeting = "Namaste, " + "RUDRA";
print(greeting + "\n");
print(to_str(str_len(greeting)) + "\n");
print(substr(greeting, 0, 7) + "\n");
return 0;
}
return main();