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

TypeDescriptionExample
intInteger42
floatFloating-point number3.14
boolBooleantrue, false
strString"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));
}