Standard Library Reference
OxigenLang's standard library is a set of .oxi modules that ship with the
interpreter. Import one with introduce:
introduce math
println(math.sqrt(16)) // 4Or pull specific names into scope:
introduce {sqrt, abs} from math
println(sqrt(16))Structs must be imported by name — introduce {Parser} from parse_args — since
a struct is not constructible through a module namespace. See
imports.md for the full import syntax.
One page per module, each documenting every callable function with examples:
#Data and text
| Module | What it covers |
|---|---|
| strings | split, join, trim, case, search, pad |
| array | map/filter/reduce, folds, search, sort, group, pmap |
| sets | union, intersection, difference, subset tests |
| math | arithmetic, rounding, trig, logs, gcd/lcm, PI/E/TAU |
| regex | match, find, captures, replace, split (Rust regex syntax) |
| json | parse/stringify, files, dotted paths, merging |
| toml | same API as json, for TOML documents |
| encoding | base64, hex, URL percent-encoding |
| hash | SHA-256, SHA-1, MD5 hex digests |
#System
| Module | What it covers |
|---|---|
| io | read/write/append files, console input |
| os | run commands, background processes, signals, environment, directories |
| path | join, split, normalize, is_within containment check |
| time | timestamps, sleep, monotonic durations |
| datetime | UTC calendar dates, formatting, parsing |
| random | random ints/floats/bools, choice, seed |
| env | load a .env file into a map |
| parse_args | command-line flag parsing |
| channel | pass messages between diverge tasks, in order |
#Network
| Module | What it covers |
|---|---|
| net | HTTP client, streaming HTTP, TCP and UDP sockets |
| api | HTTP server: routing, JSON and HTML responses, static files, the accept loop |
#C interop
| Module | What it covers |
|---|---|
| ffi | call C libraries by signature: structs, pointers, variadics, callbacks |
#Language support
| Module | What it covers |
|---|---|
| result | helpers for the Error || Value system |
| test | expect(...) matchers used by oxigen test |
| ansi | terminal colour, modifiers, cursor control |
#Conventions across the library
Errors. Two kinds show up. A catchable error is an ordinary value you can
inspect (math.factorial(-1), json.parse on bad input). A terminal error
halts the program (most of net, a missing file in io). Turn
the second into the first by normalizing the call:
r := <type<Error> || <Value>>(io.read_file("maybe.txt"))
option {
is_error(r) -> { println("failed: {r.msg}") }
{ println(r.value) }
}result has the helpers that make chains of these readable.
A module's API is what it does not hide. Top-level bindings are public by
default; a helper marked hide fun is callable only inside its own file
(array's _min_index_by and _remove_at, for instance). Struct fields take
the same keyword inside the struct body.
Reach for dot access on a key you know is there. resp.status,
data.information, john.info.job — reading or writing. A mistyped key
errors instead of silently reading None, which is the point:
resp := net.get(url)
println(resp.status) // always present — dot
println(resp.stauts) // error: key 'stauts' not found on mapBrackets are for the three cases dot cannot serve: a key that may be absent
(req.query["page"]), a key held in a variable (users[id]), and a key
that is not an identifier (headers["content-type"]). Bracket reads answer
None for a missing key, so they are also the form to use when absence is the
thing you are testing. Full rules in data_types.md.
Maps and arrays are shared references. insert, remove, push, and
every *_in/merge/set_where function in json and
toml modify the value you pass and return that same value.
Round-trip through stringify/parse for a copy of a map;
array.slice(a, 0, len(a)) copies an array.
Strings are immutable, and the array module's own functions
(map, filter, unique, …) build a new array rather than editing yours.
Sockets and streams use handles. net hands back an opaque number;
always close it.
#Where the rest of the language is documented
| Page | Contents |
|---|---|
| builtins.md | global functions — len, push, keys, range, type, has, … |
| imports.md | introduce syntax, namespacing, local modules |
| type_system.md | type annotations, Error || Value |
| angle_forms.md | <fail>, <log>, <type<...>> and friends |
| concurrency.md | diverge, converge, share-nothing threading |
| testing.md | the oxigen test runner |
The sources are worth reading — every module is plain Oxigen in stdlib/.