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() {
let name = "RUDRA";
let mut count = 3;
count = count + 1;
print(name);
print(count);
} Type annotations
You can annotate a binding with its type.
fn main() {
let title: str = "Systems language";
let answer: int = 42;
print(title);
print(answer);
} Core types
| Type | Description | Example |
|---|---|---|
int | Integer | 42 |
float | Floating-point number | 3.14 |
bool | Boolean | true, false |
str | String | "text" |
Arrays
Array literals hold a fixed set of values, indexed from zero.
fn main() {
let nums = [10, 20, 30];
print(nums[0]);
print(nums[2]);
} Strings
Strings concatenate with +, and len returns a string length.
fn main() {
let greeting = "Namaste, " + "RUDRA";
print(greeting);
print(len(greeting));
}