Types & literals
Dynamic typing: numbers, strings, booleans, arrays, maps, and `nil`.
Rain is dynamically typed. Values know their type at runtime; you don't declare types on variables.
Numbers are IEEE doubles. Whole numbers print without a trailing .0.
Strings are immutable double-quoted literals. See the Strings page for interpolation, escaping, concatenation, and the str module.
nil is the absence of a value. Only false and nil are falsy in conditions.
Arrays are first-class values created with #[ ... ]. Maps are string-keyed hash tables written { "key": value }. See the Maps page.
Use typeOf(value) to read a value's runtime type as a string, isType(value, name) to test it, and assertType(value, name) to enforce it (raises a runtime error on mismatch).
Core literals
Rain values at a glance: numbers, strings, booleans, `nil`, arrays, and maps.
print 42;
print 3.14;
print "hello";
print true;
print false;
print nil;
print #[1, 2, 3];
print {"name": "Rain", "version": 1};42
3.14
hello
true
false
nil
[1, 2, 3]
{"name":Rain, "version":1}Runtime type checking
`typeOf` returns a type string, `isType` checks without failing, and `assertType` returns the value or raises `TypeError`.
print typeOf(42);
print typeOf("hi");
print typeOf(nil);
print typeOf(#[1, 2]);
print isType(42, "number");
print isType(42, "string");
var n = assertType(42, "number");
print n;number string nil array true false 42
Runtime type names
Strings returned by `typeOf` and accepted by `isType` / `assertType` for built-in values.
| Symbol | Description |
|---|---|
"nil" | The `nil` value |
"bool" | Booleans |
"number" | Numbers (IEEE doubles) |
"string" | Strings |
"array" | Arrays (`#[ ... ]`) |
"map" | Maps (`{ ... }`) |
"function" | Functions, closures, and natives |
"class" | Class objects |
"module" | Imported modules |
"matrix" | Math matrices |
ClassName | Instances return their class name, e.g. `"Dog"` for `class Dog` |