The Journey of Building PatLang
Every other page in this section documents what PatLang is . This one documents how it got that way — pulled directly from over 200 commit messages spanning May 2025 to the present, warts included. It's written as a…
PatLang programming language, self-hosted compiler, and interactive portfolio.
Every other page in this section documents what PatLang is . This one documents how it got that way — pulled directly from over 200 commit messages spanning May 2025 to the present, warts included. It's written as a…
A direct continuation of The Journey of Building PatLang (Acts I-VI: the one-day MVP sprint through the self-hosting fixpoint through four "PatLang first" features) — split into its own page because this arc, on its…
A direct continuation of the previous instalment (Acts VII-XIV: teaching the language to induce its own code, then a third independent grammar validator and a dormant goal-oriented paradigm brought back to life) — split…
A direct continuation of the previous instalment (Acts XV-XXIII: hosting PatLang somewhere new, a real x64 code generator reaching its own fixpoint, a three-act performance saga on this very site's own build pipeline…
PatLang is not built around one programming model with the others bolted on as libraries. Nine paradigms sit at roughly equal weight in the language and its host-function surface, each with real working example code in…
Every example below is a real, verified-running PatLang program (via pat --ir-run ) — not a sketch. The first eight demonstrate one paradigm each in isolation; the fifteen after that combine two of the six "real"…
Most PatLang example programs in this site run once, print something, and exit — fine for a demo, wrong for anything meant to run as a daemon, be discovered by other processes, or be controlled from a second invocation…
Most of this comes from the same place the journey page 's lessons do: real code written this session, real bugs found while writing it, and a few habits that turned out to matter more than expected once programs got…
Language documentation tends to undersell gaps. This page does the opposite deliberately: a direct list of what PatLang currently cannot do, alongside what it genuinely can, sourced from code comments and verified…
The Paradigms Guide covers each capability in isolation. Real PatLang programs usually combine several at once — this page walks the repository's larger example programs by the problem shape they're actually solving…
The actual grammar file, published in full: docs/grammar/patlang-full.peg , the single canonical Parsing Expression Grammar behind the PEG grammar validator dev tool. It's interpreted identically by two independent…
PatLang exists in two real implementations, not one language with two front-ends bolted on. Stage 0 is the native Rust parser ( rust-runtime/src/parser.rs ) that has been there from the start. Stage 1 is the self-hosted…
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…
PatLang has always had more than one way to run a program — the tree-walking interpreter ( --ir-run ), the rustc-backed native compiler ( --patc ), and (in progress, currently on hold) a from-scratch x64/NASM backend.…
Grammar and host-function references say what's available. This page is about what to actually reach for, and why — the patterns that recur across PatLang's own compiler, standard library, and demo programs, most of…
Ordinary Int arithmetic stays on the fast path until it can't: factorial(30) overflows a 64-bit integer partway through and the runtime silently promotes to an exact, arbitrary-precision BigInt — no annotation, no…
Every one of these grew directly out of pain felt while developing PatLang itself. Debugging a real bug in self_hosting/lib/lower.patlang — a stray extra end that the native parser silently tolerated but the self-hosted…
The self-hosted compiler (lexer, parser, lowerer), compiled to WebAssembly once and reused for every run in this page. Run executes your program; Tokens and AST show the compiler's own intermediate representations for…
The self-hosted PatLang compiler (lexer, parser, lowerer) compiled to WebAssembly. Edit the program, press Run: your source is tokenized, parsed, and lowered by PatLang code running in this page, then executed on the…
A live PatLang session, running entirely in this tab -- no server involved. Each entry should be ONE statement -- a single line, or a single multi-line block like make a function called ... end -- press the Run button…
Driven by a manifest file ( self_hosting/patbuild.manifest ):
The self-hosted compiler front+middle end processing its own complete source (289918 chars), run under the Stage 0 interpreter while building this page:
The self-hosted PatLang compiler ( self_hosting/patc1_main.patlang , driving patc1.exe — see the self-hosting story for what that actually means) had a real, embarrassing gap until recently: it had no parse-error…
Paste a self-contained PatLang program (no include lines -- this instruments the text directly) and click Run. The summary table and per-function tabs below show which branches your program's own code actually took…
Recursion, control flow, lists, events (when/emit), logic (fact/query), OO (new/send/get), and functional map/filter via apply .
require checks a precondition, ensure a postcondition, and assert is the same primitive used standalone — all three lower to one contract_check host call, enforced identically whether interpreted, run here via WASM (no…
PatLang's own self-hosted Gherkin-style BDD framework ( lib/test.patlang : t_init / check / step / run_feature_tagged ), running against the point of sale: unit assertions, event-driven integration checks, and a Gherkin…
A working inductive logic programming (ILP) system, built entirely in PatLang, that treats Gherkin-style BDD scenarios ( Given / When / Then ) as a training corpus and induces real PatLang rule clauses that satisfy them…
A worked example of PatLang's goal-oriented paradigm, run live below — see the Paradigms Guide for how rule_add / solve and action_add / plan fit together, the Grammar reference for the declarative rule ... :- ...…
Real rule Head(args) :- Body. declarative syntax, run live below — see the Grammar reference for the statement grammar and the goal-oriented demo for the equivalent hand-written rule_add call form this sugars over.
Word-form bitwise operators and bitfield helpers, run live below — see the Grammar reference for precedence rules and the Standard Library reference for the full bitfield-helper list.
The DSL page above declares its syntax { ... } block as a literal, expanded once before the compiler ever runs — indistinguishable from a macro. This one instead computes its trigger keyword and rules from data at…
A self-hosted Ruby transpiler ( lib/transpile_ruby.patlang ) walking the PRE-LOWERING AST directly (real if / while / def already present, unlike the flattened jump-based IR the ordinary compiler produces) to emit…
parallel_map(items, "func_name") spawns one real OS thread per item (via Rust's std::thread::scope ) and runs func_name(item) on each concurrently — genuine parallelism, mirrored byte-for-byte into the compiled-native…
Ruby-style cooperative coroutines ( fiber_new / fiber_resume / fiber_yield / fiber_alive ), implemented on real OS threads under the hood but never actually running concurrently: a mutex+condvar pair ( ir/fiber.rs )…
Live demo of cross-thread events ( when / emit ) built directly on the fiber/threading work documented in the Paradigms Guide and the fiber demo — see also Capabilities & Honest Limitations for the underlying…
A five-part answer to a question posed mid-session: could a running PatLang program discover other running PatLang programs it didn't already know about, learn what they offer, and treat them as callable objects —…
A worked example of PatLang's runtime signals, whose native transcript is shown below — see the Paradigms Guide for the full design writeup and the Standard Library reference for tcp_try_listen and the rest of the…
An in-memory filesystem available on every target including WASM, run live below — see the Standard Library reference for the full vfs_* function list and the native-only, security-gated vfs_flush_to_disk .
One orchestrator process spawns three independent PatLang service processes as real, separate OS processes, waits for each to confirm it's genuinely ready (not just "the process started" — its own presence beacon has to…
Three independent workers, each doing risky I/O work, each with its OWN topic ( queue_writer_topic(base, worker_id) ) rather than sharing one — the queue does whole-file read-modify-write with no locking, so giving…
A worked example combining five of PatLang's less-usual capabilities into one coherent system, whose native transcript is shown below — see the goal-oriented demo for the logic/GOAP half in isolation, the signals demo…
The six self-hosted dev tools described a pattern: notice a recurring annoyance in the PatLang workflow, build a small self-hosted tool for it, verify it against the real codebase, and usually find a real bug along the…
Each example below is written in PatLang, compiled by the self-hosted PatLang compiler (lexer, parser, lowerer, and code generator all written in PatLang), and embedded here as WebAssembly. Press Run to execute it in…
A small hex-grid economy sim, running entirely in this tab. Left-click a unit to select it. Right-click a tile to send the selected unit there -- a resource tile (gold, with a number) starts an automatic gather loop…
A small transactional SQL database, running entirely in this tab. Type a statement and press Enter or Run -- try CREATE TABLE people (id INT, name STRING, age INT) , then INSERT INTO people VALUES (1, 'alice', 30) …
Build a family tree by adding child, parent relationships, then click any node to explore it. See self_hosting/lib/family_tree.patlang for the underlying ancestor/descendant/sibling logic -- a small, reusable module…
The same control-flow-graph recovery as the flowgraph CLI tool ( flowgraph <output.html> [inputs...] , source below), running live: paste a program, press Render, and see basic blocks and jump edges recovered from the…
Basic blocks and jump edges recovered from the self-hosted compiler's own IR, one section per program. Red curves are conditional (JumpIfFalse), blue are unconditional.
Basic blocks and jump edges recovered from the self-hosted compiler's own IR, one section per program. Red curves are conditional (JumpIfFalse), blue are unconditional.
PatLang computing data (a fibonacci table) and generating a well-formed, interactive HTML+JS page around it — the browser as PatLang's cross-platform GUI. Running live below: the iframe is the actual page this PatLang…
Writing the abstract requires every other section to exist first, and several sections have real sub-tasks of their own (running experiments, gathering data, and analysing it are separate delegated tasks). Each task is…
Writing the abstract requires every other section to exist first, and several sections have real sub-tasks of their own (running experiments, gathering data, and analysing it are separate delegated tasks). Each task is…
A grid compiled into logic-programming fact s, solved by a recursive depth-first search driven by query , announced with goal , and reported through a solved / unsolved event - generation and solving both run live in…
A classic for a reason: an escape-time Mandelbrot renderer, compiled from real PatLang source to WebAssembly and run live below — every pixel's iteration count is genuine PatLang computation, not a JS reimplementation…
Ported from a standalone JS/Canvas prototype into real PatLang, compiled to WASM and run live below — see the Paradigms Guide for the numeric tower this interval arithmetic builds on, and the k-blade page for the…
fib(27), a 2-million iteration loop, and a 200k-element vector build, each reporting its own elapsed milliseconds.
A checkout session as a stream of scan / pay events: the product catalog lives in the object store, and a dairy fact drives the discount rule.
A small grammar extension declared entirely in PatLang source ( syntax RouterDSL { trigger; tokens { ... }; rule { ... } } ), matching HTTP-verb/URL-path tokens with a general-purpose regex engine also written in…
If you know Python, most of PatLang's everyday syntax will feel immediately readable — but a handful of very Python-shaped habits (list comprehensions, for loops, f-strings, duck-typed classes) don't exist here at all…
Java trains you to think in classes, static types, and checked exceptions. PatLang has none of the three. This page maps Java habits onto what PatLang actually offers, and is upfront about where the two languages simply…
C gives you manual control over every byte and every allocation. PatLang gives you none of that control back, deliberately — there are no pointers, no malloc / free , and no way to reach past the language into raw…
Of the four languages covered in this series, Ruby is the closest relative — PatLang's do / end blocks and word-form keywords are a deliberate nod to Ruby's own readability-first syntax, and PatLang even ships a working…