💡 RADS Code Examples
Learn by example - comprehensive code samples for every feature
Complete Language Reference
Explore comprehensive examples covering all RADS features. Each example is runnable and demonstrates real-world usage.
🚀 Hello World
Your first RADS program
blast main() {
echo("Hello, RADS World! 🚀");
}
📦 Variables & Types
Working with different data types
blast main() {
// Numbers
turbo i32 my_integer = 42;
turbo f64 my_float = 3.14159;
// Strings
str greeting = "Hello, RADS!";
// Booleans
turbo bool is_rad = true;
// Arrays
array<i32> numbers = [10, 20, 30, 40, 50];
echo("First: " + numbers[0]);
// Dynamic arrays
dynarray<str> names = dynarray();
names.push("Alice");
names.push("Bob");
}
⚡ Functions
Defining and calling functions
// Function with parameters
blast greet(str name) {
echo("Hello, " + name + "!");
}
// Function with return value
blast add(i32 a, i32 b) -> i32 {
return a + b;
}
// Multiple return values
blast divmod(i32 a, i32 b) -> (i32, i32) {
return (a / b, a % b);
}
blast main() {
greet("RADS");
turbo i32 sum = add(5, 3);
echo("5 + 3 = " + sum);
turbo (i32 q, i32 r) = divmod(10, 3);
echo("10 / 3 = " + q + " remainder " + r);
}
🔀 Control Flow
If-else and conditionals
blast main() {
turbo i32 number = 7;
if (number > 10) {
echo("Greater than 10");
} elif (number > 5) {
echo("Greater than 5 but not 10");
} else {
echo("5 or less");
}
// String comparison
turbo str name = "RADS";
if (name == "RADS") {
echo("Hello, RADS!");
}
}
🔄 Loops
Loop and cruise iterations
blast main() {
// Loop (while loop)
turbo i32 i = 0;
loop (i < 5) {
echo("i = " + i);
i = i + 1;
}
// Cruise (for loop) over range
cruise (j in 0..5) {
echo("j = " + j);
}
// Cruise over array
array<str> names = ["Alice", "Bob", "Charlie"];
cruise (name in names) {
echo("Hello, " + name + "!");
}
}
🏗️ Structs
Custom data types
// Define a struct
struct Player {
str name;
i32 score;
bool is_active;
}
blast print_player(Player p) {
echo("Player: " + p.name);
echo("Score: " + p.score);
}
blast main() {
// Create struct instance
turbo Player p1 = Player {
name: "Xx_Rads_Gamer_xX",
score: 100,
is_active: true
};
// Modify fields
p1.score = p1.score + 50;
print_player(p1);
}
🌐 HTTP Server
Building web servers with async/await
import net;
async blast handle_home(stream req) {
return "<h1>Welcome to RADS! 🚀</h1>"
+ "<p>Blasting data at turbo speed!</p>";
}
async blast handle_api(stream path, stream method,
stream body, stream query) {
turbo json = "{\"status\":\"radical\",\"speed\":9001}";
return net.json_response(json);
}
async blast main() {
turbo server = net.http_server("0.0.0.0", 8080);
echo("🌐 Server running on http://localhost:8080");
// Register routes
net.route(server, "/", handle_home);
net.route(server, "/api", handle_api, "GET");
net.static(server, "/static", "./public");
// Start serving
await net.serve(server);
}
🎨 Web Engine
JavaScript execution and HTML/CSS parsing
blast main() {
echo("🌐 RADS Web Engine Demo");
// Initialize Web Engine
web_init();
// Execute JavaScript
js_eval("console.log('Hello from JavaScript!')");
js_eval("console.log('RADS + JS = TURBO!')");
// Parse HTML
turbo html = "<html><body><h1>Hello!</h1></body></html>";
turbo doc = html_parse(html);
turbo element = html_querySelector(doc, "h1");
// Parse CSS
turbo css = "body { color: purple; }";
turbo styles = css_parse(css);
// Load plugins
turbo markdown = pkg_load("rads-plugin-markdown");
turbo template = pkg_load("rads-plugin-template");
echo("✅ Web Engine Demo Complete!");
}
�� More Examples
Find more examples in the RADS repository:
- 01-basics/ - Variables, loops, functions, structs
- 02-networking/ - HTTP servers, clients, JSON APIs
- 03-media/ - Audio/image processing
- 04-advanced/ - FFI, plugins, advanced features
Clone: git clone https://github.com/zarigata/rads.git