Prelude and Intrinsics
The implicit environment
Every rnx source file compiles inside an implicit environment: names resolve through local scopes first, then package globals and compiler builtins, then @std/prelude. No import is required for any of these names. Explicit declarations and imports always shadow prelude names with no error.
struct Map {
let x: Int;
}
let o = Map(1);
println!(o.x);The local struct Map replaces the prelude Map for the declaring scope. Shadowing applies per scope; other files are unaffected.
Root intrinsics
Two functions are compiler builtins, available without declaration or import:
| Intrinsic | Signature | Effect |
|---|---|---|
assert | assert(condition: Bool, message: String) | Aborts with file and line diagnostics when condition is false. |
typeOf | typeOf(value) | Returns the runtime type tag, or the class identifier for objects. |
The print surface is the four @std/io macros re-exported by the prelude. print! writes its formatted arguments with no newline, and println! appends one. There is no ordinary print function.
println!("values:", 40 + 2, true);
assert(1 + 1 == 2, "arithmetic");
println!(typeOf(42), typeOf("s"));Conditional aborts use the PanicIf! macro form, which panics with the message when the condition holds:
PanicIf!(false, "unreached");
println!("alive");There is no bare panic(...) function; calling one is an E303 error. Failure inside fallible functions uses throw; see Functions and Closures.
print!, println!, eprint!, and eprintln! are prelude-visible @std/io macros: every argument runs through the shared pretty-printer (see Hardware and FFI). print! writes no newline; println! adds one.
Foundation types
These types resolve from the prelude in every file:
| Type | Meaning |
|---|---|
Int | 64-bit signed integer. |
Float | Strict IEEE-754 double. |
FastFloat | Same 64 bits with reassociation permitted. |
Bool | true or false. |
String | UTF-8 text; literals are immortal. |
Char | Single scalar view into a String. |
Array | Dense growable sequence. |
Map | Insertion-ordered key-value table. |
Set | Distinct-member collection. |
Date | Calendar view over the wall clock; declared in @std/time. |
Error | Error value. |
Any | Untyped escape hatch. |
Void | Absence of a value. |
GenRef | Generational reference for cyclic edges. |
Numeric semantics are specified in Numeric Model; memory behavior in Memory and ARC.
The stock prelude is a facade over ordinary packages. It re-exports Date from @std/time, Promise, PromiseWithResolvers, and PromiseResult from @std/async, and RnxHost from @std/env. Import those packages directly when you want the names without the prelude:
import { Clock, Date } from "@std/time";
import { Promise } from "@std/async";
import { RnxHost } from "@std/env";A selected prelude that omits Promise disables async lowering: async fn and await fail with E108 naming the prelude and Promise.
Nullable values and Result
There is no Option type. A missing value is null (type Null), and a nullable slot is written T?: Map.get(key) yields V?, Array.find(pred) yields T?, and an empty pop() yields null. ?? substitutes a fallback:
let port: Int? = null;
assert((port ?? 8080) == 8080, "fallback");
let ok: Result<Int, String> = Result.Ok(42);
println!(ok.unwrap());Result is a generic enum merged into every program: Ok carries a payload and Err carries an error. Its query methods (isOk, isErr, unwrap, unwrapOr) lower to discriminant checks. The ?, ??, and ?. channels over nullables and Result are specified in Functions and Closures.
Iteration traits
interface Iterator<T> { fn next(): T?; }
interface Iterable<T> { fn iterator(): Iterator<T>; }for..in over any Iterable desugars to a while loop over next(); see Extensions and Operators.
Array extensions
Arrays carry compiler-provided core methods plus prelude extension methods, all without import. length works as a call and as a property.
let arr = [10, 20, 30];
arr.push(40);
println!(arr.length, arr.pop());
let doubled = arr.map((x: Int) => x * 2);
let evens = arr.filter((x: Int) => x % 2 == 0);
println!(doubled.length, evens.length);Search and fold helpers:
let numbers = [10, 20, 30, 40, 50];
assert(numbers.find((n) => n > 25) == 30, "find");
assert(numbers.findIndex((n) => n == 40) == 3, "findIndex");
assert(numbers.some((n) => n == 30), "some");
assert(numbers.every((n) => n > 0), "every");
assert(numbers.reduce(0, (acc, n) => acc + n) == 150, "reduce");
assert(numbers.join(",") == "10,20,30,40,50", "join");
assert(numbers.reversed()[0] == 50, "reversed");find returns the first match as T? (null when nothing matches); findIndex returns the index or -1; some/every short-circuit (some is false and every is true on empty arrays); reduce<U> folds left with an independent accumulator type; join stringifies with a separator; reversed returns a reversed copy.
Array method reference
| Method | Signature | Empty-array result | Short-circuit |
|---|---|---|---|
find | find(pred: fn(T): Bool): T? | null | stops at first match |
findIndex | findIndex(pred: fn(T): Bool): Int | -1 | stops at first match |
some | some(pred: fn(T): Bool): Bool | false | stops at first true |
every | every(pred: fn(T): Bool): Bool | true | stops at first false |
reduce<U> | reduce<U>(initial: U, f: fn(U, T): U): U | initial | never; visits all |
join | join(separator: String = ""): String | "" | never; visits all |
reversed | reversed(): Array<T> | [] | n/a (copy) |
let empty: Array<Int> = [];
assert(empty.find((n) => n > 0) == null, "find empty");
assert(empty.findIndex((n) => n > 0) == -1, "findIndex empty");
assert(empty.some((n) => true) == false, "some empty");
assert(empty.every((n) => false) == true, "every empty");
assert(empty.reduce(9, (acc, n) => acc + n) == 9, "reduce empty");
assert(empty.join(",") == "", "join empty");
assert([3, 1].reversed()[0] == 1, "reversed");
assert([1, 2, 3].join() == "123", "join default");The predicate runs once per element in index order. reduce<U> takes an independent accumulator type U, so the accumulator need not match the element type.
let words = ["a", "bb"];
assert(words.reduce(0, (acc, w) => acc + w.length()) == 3, "fold types");Result method reference
| Method | Signature | Ok(v) | Err(e) |
|---|---|---|---|
isOk | isOk(): Bool | true | false |
isErr | isErr(): Bool | false | true |
unwrap | unwrap(): T | v | aborts with a fatal diagnostic |
unwrapOr | unwrapOr(fallback: T): T | v | fallback |
let ok: Result<Int, String> = Result.Ok(42);
assert(ok.isOk() && !ok.isErr(), "ok flags");
assert(ok.unwrap() == 42, "unwrap ok");
assert(ok.unwrapOr(-1) == 42, "unwrapOr ok");
let bad: Result<Int, String> = Result.Err("down");
assert(bad.isErr() && !bad.isOk(), "err flags");
assert(bad.unwrapOr(-1) == -1, "unwrapOr err");Intrinsic reference
| Intrinsic | Signature | Failure mode |
|---|---|---|
assert(cond, msg) | assert(Bool, String) | aborts with file and line when cond is false |
typeOf(value) | any value | never fails; returns the runtime type tag or class identifier |
PanicIf!(cond, msg) | PanicIf!(Bool, String) | aborts when cond is true |
println!("one", 2, false);
PanicIf!(1 + 1 == 3, "math broke");
println!(typeOf(42));
println!(typeOf("s"));String extensions
Core methods (length(), slice, indexOf, trim, concat, charCodeAt) are specified in Lexicon and Structure. Search and transform helpers arrive via the prelude with no import:
let greeting = "hello world from rasmalai";
assert(greeting.contains("world"), "contains");
assert(greeting.startsWith("hello"), "prefix");
assert(greeting.endsWith("rasmalai"), "suffix");
let parts = greeting.split(" ");
assert(parts.length() == 4 && parts[0] == "hello", "split");
assert("foo bar foo".replace("foo", "baz") == "baz bar foo", "replace");
assert("foo bar foo".replaceAll("foo", "baz") == "baz bar baz", "replaceAll");
assert("na ".repeat(3) == "na na na ", "repeat");
assert("hello".toUpperCase() == "HELLO", "toUpperCase");
assert("HeLLo".toLowerCase() == "hello", "toLowerCase");split("") splits into one string per character; replaceAll with an empty target returns the string unchanged. toUpperCase and toLowerCase fold ASCII letters only, so digits and punctuation stay put and accented Latin passes through untouched: "héllo".toUpperCase() gives "HéLLO".
Scope-builtin types
IO, Thread, and ThreadPool are declared by the selected prelude as catalog stubs, and their methods are compiler-lowered. A prelude that omits one of them makes that name unavailable, so a target prelude chooses which ambient surfaces exist. Pointer and Address remain compiler builtins regardless of the prelude. Threading is specified in Concurrency and Threads; raw pointers and C-ABI in Hardware and FFI.
Summary
- Resolution order: local scopes, then globals and builtins, then
@std/prelude; explicit declarations shadow prelude names. - Root intrinsics:
assertandtypeOf, plus thePanicIf!macro form. The print family comes from@std/iothrough the prelude. No barepanic()exists. - Foundation types,
null/T?andResult, and iteration traits resolve everywhere. - The stock prelude re-exports
@std/time,@std/async, and@std/env;IO,Thread, andThreadPoolexist only when the selected prelude declares them. - Array and String extensions (
find,reduce,contains,split, and siblings) require no import.