Core I/O & values

CallDescription
@stdout(fmt, .{}) / @stderr / @logFormat output; only {} placeholders, exact count match required.
std.print(fmt, .{})Namespaced spelling of @stdout (requires std import).
print(x) / println(x)(selfhost bridge) host-side print used inside interpreted programs.
len(v)Length of str / array / map entries.
int(v) · float(v) · str(v)Conversions; int truncates toward zero.
@as(type, v)Cast with alias table: i32/i64/u8/u32/u64/usize→int, f32/f64→float, string→str, bool→truthy. Unknown type = compile error.
env("KEY") · clock()Environment lookup ("" if unset); seconds since VM start.
read_file(p) / write_file(p,d) / file_exists(p)Filesystem (Io-backed).
args()CLI argument vector as array of strings.
@vector(n,t) / @splat(n,v) / @reduce(op,xs)Vector intrinsics (interpreted scalar fallback; op ∈ add/mul/min/max).
select(cond,a,b)Branch-free select.

Strings

CallDescription
split(s, sep) / join(arr, sep)Split into array / join array of strings.
trim(s)Strip surrounding whitespace.
replace(s, old, new)Replace all occurrences.
contains(hay, needle)Substring test → bool.
starts_with(s,p) / ends_with(s,suf)Prefix/suffix tests.
to_lower(s) / to_upper(s)ASCII case conversion.
slice(v, a, b)Slice str or array, end-exclusive; negatives from end.

Arrays & maps

CallDescription
push(arr, v)Returns a NEW array with v appended (functional growth).
.{ k = v }Map literal (string keys). Empty .{} is the format tuple — use map_new().
m["key"] / m["key"] = vGet (missing → null) / set by string key.
m.keys() / m.values()Iterate contents (order unspecified).
m.has(k) / m.remove(k)Membership / delete.
map_new()Fresh empty map.

JSON & CSV

CallDescription
json_parse(text)Objects→maps, arrays→arrays; invalid input is a runtime error.
json_stringify(v)Maps/arrays/scalars to JSON text (key order unspecified).
csv_parse(text)RFC4180-ish: quotes, "" escapes, embedded commas/newlines, CRLF.
csv_format(rows)Render rows; quotes cells containing , " or newlines.

Crypto & assertions

CallDescription
sha256(s)64-char lowercase hex digest.
base64_encode(s) / base64_decode(s)Standard alphabet; invalid input rejected.
assert(cond) / assert_eq(a,b)Runtime checks; assert_eq prints both values on failure.
panic(msg)Raise a catchable runtime error carrying msg.
try(fn_call())Run one call guarded → [ok, result_or_message]; nested try works.
log_write(level, msg)Structured stderr line "[INFO] msg"; level int 0..4 or custom tag.

tensor @tensor core

FormDescription
@tensor(dtype, [shape], .{.device=.cpu, .fill=v})Contiguous row-major tensor; cuda/rocm degrade with clear error in v1.
t[i] / t[i] = vLinear indexing; out-of-bounds is a runtime error.
t.shape() t.numel() t.dtype() t.data() t.fill(v) t.deinit()Methods; deinit idempotent, later use rejected. defer cannot capture locals — call explicitly.
t.apply_simd(fn(x: @vector(N,T)) T { ... })Element-wise kernel, runs in place; lane width is a hint.

ai zero-copy readers

CallDescription
load_safetensors(path)Array of named read-only tensor views over mmap. F32/F64/I32/I64.
load_gguf(path)GGUF v2/v3; ggml NE dims reversed to row-major; F32/I32/I64/F64 dtypes.

llm transformer

CallDescription
llm_load(path)GGUF model using the rinne.llm.* metadata convention (see docs/libs/llm.md).
m.forward(.{ids...})Last-token logits over F32 weights (RMSNorm·RoPE·GQA·SwiGLU).
m.deinit()Idempotent close; later use rejected.

net tcp

CallDescription
tcp_listen(port)Listener on 0.0.0.0; port 0 = ephemeral, discover via l.port().
tcp_connect(host, port)Stream to remote host.
l.accept() / l.port() / l.close()Accept one stream; bound port; close listener.
s.read(max) / s.write(str)Up-to-max bytes (returns early at EOF); write flushes before returning.
s.shutdown(how)Half-close: send|recv|both (default send) — frame messages on blocking platforms.
s.close()Close stream.

c dlopen FFI

CallDescription
load_lib(name)Open shared library; sonames resolve via the system loader ("libc.so.6").
lib.call_int(sym, .{args≤4})Call C function returning i64.
lib.call_float(sym, .{args≤4})Call C function returning f64 (note: fabs lives in libm).
lib.deinit()dlclose; idempotent.