Reference · 04
Built-in Functions & Standard Library
Complete signature reference for all built-in functions in Ochre v0.1.0-alpha.4 — I/O, conversions, collections, strings, files, JSON, HTTP, and concurrency.
Every function listed below is built into the Ochre runtime and available in all programs with zero imports.
I/O, Terminal & Environment
| Function | Return Type | Runtime | Description |
|---|
print(val) | Void | VM, AOT, WASM | Print value to stdout without trailing newline |
println(val) | Void | VM, AOT, WASM | Print value to stdout with trailing newline |
input(prompt: Str) | Str | VM (CLI) | Display prompt and read one line from stdin |
args() | List<Str> | VM (CLI) | Return script arguments passed after the .och path |
env(key: Str) | Str? | VM (CLI) | Read environment variable (Some(val) or None) |
Conversions, Inspection & Assertions
| Function | Return Type | Runtime | Description |
|---|
int(val) | Int | VM, WASM | Convert Int, Float, Str, or Bool to Int |
float(val) | Float | VM, WASM | Convert Int, Float, or Str to Float |
str(val) | Str | VM, WASM | Convert any value to its string representation |
len(col) | Int | VM, WASM | Length of Str (chars), List<T>, or Map<K, V> |
type_of(val) | Str | VM, WASM | Return runtime type name ("Int", "List", "Struct", etc.) |
assert(cond: Bool) | Void | VM, WASM | Abort with error if cond is false |
Collections & Strings
| Function | Return Type | Runtime | Description |
|---|
push(list: List<T>, elem: T) | List<T> | VM, WASM | Return new Copy-on-Write list with elem appended |
keys(map: Map<K, V>) | List<K> | VM, WASM | Return sorted list of map keys |
contains(col, item) | Bool | VM, WASM | Check substring (Str), element (List), or key (Map) |
map(list: List<T>, f: fn(T) -> U) | List<U> | VM, WASM | Transform every element into a new list |
filter(list: List<T>, p: fn(T) -> Bool) | List<T> | VM, WASM | Keep elements matching predicate p |
reduce(list: List<T>, init: A, f: fn(A, T) -> A) | A | VM, WASM | Fold list into a single accumulated value |
split(s: Str, sep: Str) | List<Str> | VM, WASM | Split string by delimiter |
trim(s: Str) | Str | VM, WASM | Strip leading and trailing whitespace |
Files, JSON & HTTP
| Function | Return Type | Runtime | Description |
|---|
read_file(path: Str) | Str!Str | VM (CLI) | Read UTF-8 file contents |
write_file(path: Str, data: Str) | Void!Str | VM (CLI) | Write UTF-8 text to disk |
json_parse(raw: Str) | Any!Str | VM, WASM | Parse JSON text into dynamic Ochre values |
json_stringify(val) | Str | VM, WASM | Serialize Ochre value to compact JSON |
http_serve(port: Int, handler) | Void!Str | VM (CLI) | Multi-threaded HTTP/1.1 server on 127.0.0.1:port |
Concurrency & Timing
| Function | Return Type | Runtime | Description |
|---|
join(task: Task<T>) | T | VM (CLI) | Block until spawned task finishes and return its value |
channel() | Channel<T> | VM (CLI) | Create a thread-safe unbounded typed channel |
send(ch: Channel<T>, val: T) | Void | VM (CLI) | Send a value into a channel |
recv(ch: Channel<T>) | T? | VM (CLI) | Receive next value (Some(v)) or None when closed & empty |
close(ch: Channel<T>) | Void | VM (CLI) | Close channel so waiting/future recv calls terminate |
sleep(ms: Int) | Void | VM (CLI) | Sleep current thread for ms milliseconds |
clock() | Float | VM (CLI) | Monotonic wall-clock timestamp in seconds |