PatLang Standard Library & Host Function Reference
Most of what PatLang can do lives behind function calls rather than grammar — see the Grammar & Syntax page for what's actually parsed. This page catalogues that surface at two levels: the built-in host functions implemented directly in the Rust runtime and organised into named chunks, and the PatLang-level library — real .patlang source files under self_hosting/lib/ that build on those hosts.
The chunk system
Host functions are grouped into named chunks (ChunkId values), each contributing a fixed slice of Rust prelude text to a compiled program. A program only pulls in the chunks it actually uses — this is PatLang's dead-code elimination, and it currently operates at whole-chunk granularity, not per-function. Two chunks cross-depend on each other structurally: math pulls in numeric_tower, and oo pulls in logic (because send's relation-inference dispatch reads state declared by the logic chunk). numeric_tower itself is a real chunk with no named entry point — it's selected whenever an operation actually needs the full numeric tower, not called directly.
core
list_get, list_len, list_push, list_set, type_of.
strings_ext
char_code, substr, chr, to_num, hash_string.
collections_handles
A parallel, handle-based collection API alongside the plain-list functions in core: vec_new, vec_push, vec_set, vec_get, vec_len, vec_to_list, plus string-builder helpers sb_new, sb_push, sb_str, and interned-string helpers str_intern, sc_len, sc_code, sc_char. See Idioms & Patterns for when to reach for a handle-based vec_* over a plain list_*.
files
read_file, write_file, touch_file, file_exists. Note the Windows gotcha documented in the PatLang repo's own CLAUDE.md: exec_capture-style process launches need a path separator in the executable name (./patc1.exe, not bare patc1.exe) — CreateProcess's SafeProcessSearchMode excludes the working directory when searching for a bare filename, even though file_exists correctly reports the file present.
io_misc
now_ms, byte_length, read_line, argv, print, plus a set of small arithmetic/utility helpers that predate the dedicated math chunk: sed, add, multiply, subtract, max, min, calculate, calculate_result, get_value, process, validate, len.
oo
new, set_var, get, send — the entire object-orientation surface described in the Paradigms Guide.
logic
fact, query, goal, plus infer_type_for. Note from logic_engine.rs: query currently supports direct fact lookup only — rule-based inference over declared rules is not yet implemented, an honest gap worth knowing about before reaching for anything more elaborate than "does this fact exist."
contracts
One function, contract_check, backing all of require/ensure/assert — see the contracts section of the Paradigms Guide.
networking
tcp_listen, tcp_connect, tcp_accept, tcp_accept_timeout, tcp_read, tcp_write, tcp_close, sleep_ms. Raw sockets, no HTTP framing built in — the Ollama client and the echo server both hand-roll HTTP/1.1 on top of these.
codegen_bootstrap
parse_tiny_source, lower_and_compile, emit_rust_for, copy_file, patc_compile_from_argv, get_argv, rustc_build, run_ir — the primitives the self-hosted compiler pipeline itself is built from.
math
sqrt, pow, sin, cos, tan, asin, acos, atan, atan2, log, exp, floor, ceil, round, trunc, abs, numeric_kind. sqrt promotes a negative real input to Complex but explicitly rejects a Complex input — there is no complex square root.
Outside the chunk system: parallel_map, fibers, and budgeted
parallel_map, the four fiber functions (fiber_new, fiber_resume, fiber_yield, fiber_alive), and the two functions backing budgeted(...) (budgeted_run, budget_check — not normally called directly, emitted by the lowerer wherever budgeted(...) appears in source) are real, working, but genuinely not part of HOST_CHUNK_TABLE — they're special-cased by name directly in the interpreter and Rust codegen rather than routed through the generic chunk-prelude mechanism everything above uses. This is a real structural asymmetry, not an oversight to gloss over: it means the dead-code-elimination and cross-chunk-dependency machinery described above simply doesn't apply to concurrency. All three work across interpreted, natively-compiled, and self-hosted-compiled programs alike — fibers used to be interpreter-only, but compiled-native fiber support has since been ported directly into the generated program's own runtime text (mirrored in self_hosting/lib/runtime_rs.patlang). WASM is now a split, not a flat "no": the ordinary wasm32-wasip1 target still has no real OS-thread support, so all of these still return a clear runtime error there, but a second, opt-in wasm32-wasip1-threads target (nightly toolchain, atomics codegen flags) genuinely runs fibers and budgeted(...), verified both under wasmtime and live in a real browser via a hand-rolled WASI-threads JS shim (see the fiber demo). parallel_map's cfg gate now compiles for the threaded target too, in principle, but that path is unverified/undemoed so far.
The PatLang-level library (self_hosting/lib/*.patlang)
Above the host-function floor sits a real standard library written in PatLang itself:
- math.patlang — factorial, is_prime, hypot, gcd, lcm, clamp, sign, mean, built on the host
mathchunk. - json.patlang — a minimal recursive-descent JSON parser (objects, arrays, escaped strings, numbers, true/false/null) producing tagged-list values.
- markdown.patlang — the Markdown-subset renderer this very site's generator uses (headings with TOC IDs, fenced code, bullet lists, tables, inline code/bold/links).
- regex.patlang / regex_dsl.patlang — a general-purpose regex engine written in pure PatLang, with a Stage-1-dialect twin restricted to self-hosted-pipeline-available host functions.
- report.patlang — a project-report simulator: goal-oriented task dependency resolution, worker roles as objects, QA-gated stages, a virtual clock for animated timeline replay.
- maze.patlang — a maze solver combining logic-programming facts, goal-oriented search, and event-driven solved/unsolved reporting.
- pos.patlang — a point-of-sale library: events for scan/pay, a product catalogue as objects, a dairy-discount rule as logic.
- ollama.patlang — a shared Ollama HTTP client built directly on raw TCP sockets, including chunked-response handling.
- test.patlang — a test framework: plain unit assertions plus a Gherkin-style feature runner with text-registered step definitions.
- reflect.patlang — reflection: turns source text into its own AST, then into JSON, by reusing the self-hosted lexer and parser as a library.
- transpile_ruby.patlang — transpiles the self-hosted AST to idiomatic Ruby, explicitly raising on any construct or host call it can't translate rather than emitting silently-broken output.
- template.patlang — the general page/section templating library this site's own PatLang-authored portfolio pages are built with, using a tagged-tuple data model and one recursive dispatch function.
- event_loop.patlang — a reusable single-threaded, JS/Node-style event loop built on
tcp_accept_timeoutandsleep_ms. - html.patlang — an HTML5/JS page builder, used wherever the browser is PatLang's GUI.
- syntax_dsl.patlang — the self-hosted-dialect twin of the native CLI's DSL preprocessor, expanding
syntax NAME { ... }blocks on raw source before lexing.
Three further files are compiler internals rather than application library, listed here for completeness: lexer.patlang, parser.patlang, and lower.patlang (the self-hosted front end) and codegen.patlang/runtime_rs.patlang (the self-hosted back end and its generated runtime prelude mirror).
See also
- Paradigms Guide — the paradigms this surface is organised to support.
- Idioms & Patterns — when to prefer one part of this surface over another.
- Capabilities & Honest Limitations — gaps in this surface, stated plainly.