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.

Minimal program shape
benutzen "math";

var xs = #[1, 2, 3];
print math::sqrt(16);
print xs->len();
output
4
3

Keywords

Reserved words in the Rain language.

SymbolDescription
varVariable declaration
funNamed function or anonymous `fun(params) { }` expression
classClass declaration
benutzenImport a built-in or `.rn` module
if / elseConditional
whileLoop
forC-style loop, `for (item von array)`, or `for (key, value von map)`
vonFor-each: `for (item von array)` or `for (k, v von map)`
break / continueExit or skip loop iterations
versuch / fang (try/catch)Try / catch runtime errors
returnReturn from function
printOutput with newline
and / orLogical operators
true / false / nilLiterals
thisCurrent instance
superSuperclass method call

Syntax forms

Common expression and statement shapes at a glance.

SymbolDescription
#[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?.fieldOptional chaining: `nil` receiver short-circuits to `nil`
obj?.a?.bChained 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 < ParentInheritance