Bbetlang

Standard library

The built-in intrinsics: compiler-lowered calls, grouped by namespace.

The bet standard library is a pile of compiler intrinsics, not source you can go read. pull "spill" (and friends) is a no-op that just makes the namespace name available; the compiler lowers each namespace.method call straight to a runtime primitive. So these are built-in calls, neither keywords nor library files. Name a local variable the same thing and it shadows the namespace, which is exactly how a program gets to define its own net, time, or str module without a fight.

Only intrinsics that actually exist and run are listed here, no vaporware. The I badge means the call works in the interpreter (bet run); C means it works in the compiled backend. Most do both.

Graphics, audio, and input live in their own namespace; see Graphics (gg).

Reserved but not implemented yet (so pull treats them as intrinsics, not files): fmt, time, and net have no methods wired up. On strings, + is the concatenation operator.

Iruns in the interpreter (bet run)Cruns in the compiled backend
spill
spill.itIC
spill.it(x) -> void

Print x in its display form plus a newline. Type-directed: ints, floats, bool → nocap/cap, ghosted, and string literals each print correctly.

spill.fIC
spill.f(fmt, args…) -> void

Formatted print, no trailing newline. fmt is a literal string; {} are filled left-to-right; {{ }} are literal braces.

str
str.lenIC
(s: str) -> int

Byte length.

str.atIC
(s: str, i: int) -> int

Byte at index i (0–255); traps out of range.

str.subIC
(s: str, start: int, end: int) -> str

Substring s[start..end] (shares storage).

str.bytesIC
(s: str) -> []u8

Byte-slice view.

str.fromBytesIC
(b: []u8) -> str

Checked UTF-8; empty string on malformed input.

str.fromBytesTrustIC
(b: []u8) -> str

Unchecked, zero-copy []u8 → str.

str.glowIC
(s: str) -> str

Uppercase.

str.slapsIC
(a: str, b: str) -> bool

Byte equality.

str + strIC
str + str -> str

Concatenation (operator, not a method).

math
math.cookIC
(seed: int) -> rng

Seeded PRNG handle (xoshiro256** / SplitMix64). Deterministic and bit-identical across interp and compiled.

math.lapC
(a: T, b: T) -> T

Explicit wrapping add, any width/signedness (the escape hatch from signed-overflow-traps).

rng handle
.rollIC
() -> int

Raw next 64-bit draw.

.fracIC
() -> float

Float in [0.0, 1.0) (the RND analog).

.upToIC
(n: int) -> int

Unbiased int in [0, n).

sys
sys.argcIC
() -> int

Argument count (always ≥ 1; argv[0] exists).

sys.argIC
(i: int) -> str

Argument i; empty string out of range.

sys.peepIC
() -> str

Read one line from stdin, trailing newline stripped; empty at EOF.

fs
fs.peepIC
(path: str) -> []u8

Read a whole file as bytes; empty slice on error.

fs.peepTextC
(path: str) -> str

Read a whole file as a string.

fs.dropIC
(path: str, data: []u8) -> bool

Create-or-truncate write; returns success.

bytes
bytes.readU32leIC
(buf: []u8, off: int) -> int

Little-endian u32 at off.

bytes.readU16leIC
(buf: []u8, off: int) -> int

Little-endian u16.

bytes.readI16leIC
(buf: []u8, off: int) -> int

Little-endian signed i16 (sign-extended).

mem
mem.scratchIC
() -> crib

The per-frame auto-evicted arena.

mem.slab[T]IC
(n: int) -> []T

A zero-initialized buffer of n elements — the core buffer primitive.

stash
stash.new[K,V]IC
() -> stash[K,V]

Empty map. Optional allocator context: stash.new[K,V](in: crib).

.putIC
(k: K, v: V) -> void

Insert / overwrite.

.peepIC
(k: K) -> (V, bool)

Lookup; the 2nd value is a found-flag.

.yeetIC
(k: K) -> bool

Delete; returns was-present.

.gangIC
() -> int

Entry count.

vec
vec.new[T]IC
() -> vec[T]

Empty growable vec.

.stackIC
(x: T) -> void

Push.

.popIC
() -> T

Remove & return the last element.

.gangIC
() -> int

Length.

.appendIC
(s: str) -> void

Append a string's bytes (vec[u8] string builder).

.strIC
() -> str

Collect a vec[u8] into an owned str.

squadops
.gangIC
() -> int

Length.

.stack / .popIC
push / pop

On a fixed array, mutate in place; on a vec, go through the handle.

.vibeCheckIC
(pred) -> []T

Filter by a predicate function.

.glowUpIC
(fn) -> []U

Map through a function.

yikes
yikes.newIC
(msg: str) -> yikes

Construct an error value.

.teaIC
err.tea(ctx: str) -> yikes

Wrap an error, prefixing context ("ctx: msg").