Last updated: 2026-11-15
PatLang Standard Library & Host Function Reference
For new readers
A "host function" is a built-in function implemented in the underlying Rust runtime rather than written in PatLang itself โ things like list_push or vfs_read below. This page is an alphabetised-by-topic catalogue of that surface, grouped into "chunks" (explained in the section just below โ essentially a bundling/dead-code-elimination mechanism, not something you need to think about to just call the functions). Use this page for lookup once you know roughly what you're after; the Paradigms Guide is a better starting point if you're still building a mental model of what PatLang can do.
set_var, get("__vars", ...)) were removed, new gives the object rather than its name, and a field is set with obj.field = value; a call must pass exactly the arguments a function takes; and programs run on v2_interp.exe or compile with v2.exe, not pat and patc1. Values, objects and operator events and functions and calls describe the 2.0 forms, and what changed since v1 lists every change.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 chunk with no named entry point โ it's selected whenever an operation actually needs the full numeric tower, not called directly.one call can pull in its whole chunk
core
list_get, list_len, list_push, list_set, type_of. Note: list_push/list_set clone the whole backing list on every call unless the caller is the sole owner โ see Best Practices for when to reach for the handle-based vec_* builders below instead.n pushes, n copies each: quadratic loops
Bitfield helpers
bit_get, bit_set, bit_slice, bit_set_slice โ read/write individual bits or bit ranges of an integer. See the Grammar reference for the word-form bitwise operators (band/bor/bxor/shl/shr) these helpers complement, and the bitwise demo for both in a worked example.
Virtual filesystem
vfs_read, vfs_write, vfs_append, vfs_exists, vfs_list, vfs_delete โ an in-memory filesystem available on every target including WASM, unlike read_file/write_file (real, native-only disk I/O). vfs_append pushes onto the existing stored string directly โ true O(new content) amortised, not a read-modify-write of everything already there. A separate, explicit, native-only vfs_flush_to_disk write-throughs to real files, gated by an allowed-root check. See the VFS demo for a full worked example.nothing hits disk until you flush it
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 plain object-store primitives โ plus class_def, the host function the real class NAME [inherits PARENT] { ... } grammar (see the Grammar reference) lowers to: registers a class's field defaults, methods, and composed traits once, so a later new(class, id) can resolve them. See the Paradigms Guide for the full object-orientation surface, plain and class-based alike.
logic
fact, query, goal, infer_type_for โ direct fact lookup, no rule-based inference. Real rule-based inference with backtracking lives in this same chunk's rule_add/solve/goal_def/action_add/action_bind/action_lookup/action_label_args/plan/pursue โ see the Rule Declarations grammar section for the real rule/goal declarative syntax these back, and the goal-oriented demo for a full worked example of the planner.
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. rustc_build_chunked and rustc_build_chunked_texts are the chunk-precompile-and-link alternative to rustc_build's "concatenate everything, recompile from scratch" approach โ see Act XXI for the story and the ~5.7ร measured win on repeated small-program compiles, and The PatLang Compiler Pipeline for how the lower/emit_rust/emit_x64/emit_wasm/interpret pipeline stages fit together, including the self-hosted meta-circular interpreter.
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. 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.fibers take turns, threads run at once
The PatLang-level library (self_hosting/lib/*.patlang)
Above the host-function floor sits a 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 & Known Limitations โ gaps in this surface, stated plainly.
Graduate Attributes
Modelled on this page
- Digitally Fluent: Technical distinctions between runtime implementations and high-level abstractions are explained with precision.
- Subject Specialist: Systematic knowledge of the language is presented through a structured catalogue of functions and their specific use cases.
- Critical Thinker: Potential pitfalls such as platform-specific path issues are identified and documented alongside the relevant functions.
University of Reading Graduate Attributes framework.