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.

.rnx
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:

IntrinsicSignatureEffect
assertassert(condition: Bool, message: String)Aborts with file and line diagnostics when condition is false.
typeOftypeOf(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.

.rnx
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:

.rnx
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:

TypeMeaning
Int64-bit signed integer.
FloatStrict IEEE-754 double.
FastFloatSame 64 bits with reassociation permitted.
Booltrue or false.
StringUTF-8 text; literals are immortal.
CharSingle scalar view into a String.
ArrayDense growable sequence.
MapInsertion-ordered key-value table.
SetDistinct-member collection.
DateCalendar view over the wall clock; declared in @std/time.
ErrorError value.
AnyUntyped escape hatch.
VoidAbsence of a value.
GenRefGenerational 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:

.rnx
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:

.rnx
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

.rnx
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.

.rnx
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:

.rnx
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

MethodSignatureEmpty-array resultShort-circuit
findfind(pred: fn(T): Bool): T?nullstops at first match
findIndexfindIndex(pred: fn(T): Bool): Int-1stops at first match
somesome(pred: fn(T): Bool): Boolfalsestops at first true
everyevery(pred: fn(T): Bool): Booltruestops at first false
reduce<U>reduce<U>(initial: U, f: fn(U, T): U): Uinitialnever; visits all
joinjoin(separator: String = ""): String""never; visits all
reversedreversed(): Array<T>[]n/a (copy)
.rnx
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.

.rnx
let words = ["a", "bb"];
assert(words.reduce(0, (acc, w) => acc + w.length()) == 3, "fold types");

Result method reference

MethodSignatureOk(v)Err(e)
isOkisOk(): Booltruefalse
isErrisErr(): Boolfalsetrue
unwrapunwrap(): Tvaborts with a fatal diagnostic
unwrapOrunwrapOr(fallback: T): Tvfallback
.rnx
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

IntrinsicSignatureFailure mode
assert(cond, msg)assert(Bool, String)aborts with file and line when cond is false
typeOf(value)any valuenever fails; returns the runtime type tag or class identifier
PanicIf!(cond, msg)PanicIf!(Bool, String)aborts when cond is true
.rnx
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:

.rnx
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: assert and typeOf, plus the PanicIf! macro form. The print family comes from @std/io through the prelude. No bare panic() exists.
  • Foundation types, null/T? and Result, and iteration traits resolve everywhere.
  • The stock prelude re-exports @std/time, @std/async, and @std/env; IO, Thread, and ThreadPool exist only when the selected prelude declares them.
  • Array and String extensions (find, reduce, contains, split, and siblings) require no import.