Language Fundamentals
A RUDRA program is a set of functions. A file's top-level statements run in order, and the conventional last line is return main();.
Program structure
A file containing only fn main() {...} prints nothing. End the file with return main();; the exit status is the value main returns. This program prints Hello, RUDRA!.
fn main() -> int {
print("Hello, RUDRA!\n");
return 0;
}
return main(); Statements
Statements end with a semicolon. Bindings, assignments, function calls and control-flow blocks make up the body of a function.
Comments
RUDRA supports line comments that start with //. Block comments (/* ... */) are not supported. This documentation keeps its samples comment-free.
Printing
The built-in print takes only a str and adds no newline. Convert other values first: to_str for integers, and bool_to_str (module convert) and fmt_f64 (module fmath) for booleans and floats. Programs that import std modules are compiled with rudra. This program prints text, 42, 3.14 and true, each on its own line.
import "fmath";
import "convert";
fn main() -> int {
print("text\n");
print(to_str(42) + "\n");
print(fmt_f64(3.14, 2) + "\n");
print(bool_to_str(true) + "\n");
return 0;
}
return main();