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

FunctionReturn TypeRuntimeDescription
print(val)VoidVM, AOT, WASMPrint value to stdout without trailing newline
println(val)VoidVM, AOT, WASMPrint value to stdout with trailing newline
input(prompt: Str)StrVM (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

FunctionReturn TypeRuntimeDescription
int(val)IntVM, WASMConvert Int, Float, Str, or Bool to Int
float(val)FloatVM, WASMConvert Int, Float, or Str to Float
str(val)StrVM, WASMConvert any value to its string representation
len(col)IntVM, WASMLength of Str (chars), List<T>, or Map<K, V>
type_of(val)StrVM, WASMReturn runtime type name ("Int", "List", "Struct", etc.)
assert(cond: Bool)VoidVM, WASMAbort with error if cond is false

Collections & Strings

FunctionReturn TypeRuntimeDescription
push(list: List<T>, elem: T)List<T>VM, WASMReturn new Copy-on-Write list with elem appended
keys(map: Map<K, V>)List<K>VM, WASMReturn sorted list of map keys
contains(col, item)BoolVM, WASMCheck substring (Str), element (List), or key (Map)
map(list: List<T>, f: fn(T) -> U)List<U>VM, WASMTransform every element into a new list
filter(list: List<T>, p: fn(T) -> Bool)List<T>VM, WASMKeep elements matching predicate p
reduce(list: List<T>, init: A, f: fn(A, T) -> A)AVM, WASMFold list into a single accumulated value
split(s: Str, sep: Str)List<Str>VM, WASMSplit string by delimiter
trim(s: Str)StrVM, WASMStrip leading and trailing whitespace

Files, JSON & HTTP

FunctionReturn TypeRuntimeDescription
read_file(path: Str)Str!StrVM (CLI)Read UTF-8 file contents
write_file(path: Str, data: Str)Void!StrVM (CLI)Write UTF-8 text to disk
json_parse(raw: Str)Any!StrVM, WASMParse JSON text into dynamic Ochre values
json_stringify(val)StrVM, WASMSerialize Ochre value to compact JSON
http_serve(port: Int, handler)Void!StrVM (CLI)Multi-threaded HTTP/1.1 server on 127.0.0.1:port

Concurrency & Timing

FunctionReturn TypeRuntimeDescription
join(task: Task<T>)TVM (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)VoidVM (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>)VoidVM (CLI)Close channel so waiting/future recv calls terminate
sleep(ms: Int)VoidVM (CLI)Sleep current thread for ms milliseconds
clock()FloatVM (CLI)Monotonic wall-clock timestamp in seconds