Keywords & syntax
Quick cheat sheet for Rain syntax.
Rain is expression-oriented with C-like blocks. Statements end with ;. Blocks use { }.
Import modules with benutzen. User .rn files export every top-level binding by default: call them with module::name().
Minimal program shape
Import a module, use a variable, and call a function.
benutzen "math";
var xs = #[1, 2, 3];
print math::sqrt(16);
print xs->len();output
4 3
Keywords
Reserved words in the Rain language.
| Symbol | Description |
|---|---|
var | Variable declaration |
fun | Named function or anonymous `fun(params) { }` expression |
class | Class declaration |
benutzen | Import a built-in or `.rn` module |
if / else | Conditional |
while | Loop |
for | C-style loop, `for (item von array)`, or `for (key, value von map)` |
von | For-each: `for (item von array)` or `for (k, v von map)` |
break / continue | Exit or skip loop iterations |
versuch / fang (try/catch) | Try / catch runtime errors |
return | Return from function |
print | Output with newline |
and / or | Logical operators |
true / false / nil | Literals |
this | Current instance |
super | Superclass method call |
Syntax forms
Common expression and statement shapes at a glance.
| Symbol | Description |
|---|---|
#[a, b, c] | Array literal |
{"a": 1, "b": 2} | Map literal: string keys, any values |
arr[i] | Array index get / set |
map["key"] | Map get / set: missing keys return nil |
map->len() | Map method: len, keys, values, has, delete |
arr->len() | Array method call |
obj?.field | Optional chaining: `nil` receiver short-circuits to `nil` |
obj?.a?.b | Chained optional access through nested instance fields |
for (x von arr) | Iterate every element of an array |
for (k, v von map) | Iterate every key/value pair of a map |
{} | Empty map literal |
fun(x) { } | Anonymous function expression |
fun(a, ...rest) | Variadic function: `...rest` must be last; extra args become an array |
"hello #{name}" | String interpolation: any expression inside #{...} |
\#{literal} | Escaped hash: prints #{literal} without interpolating |
\"quote\" | Escaped quote inside a string literal |
"a" + "b" | String concatenation; numbers and booleans coerce to strings |
vakya(x) / toString(x) | Global built-in: convert any value to a string |
math::sqrt(9) | Module function call |
class Child < Parent | Inheritance |