PatLang

PatLang programming language, self-hosted compiler, and interactive portfolio.

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 Paradigms Guide

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…

PatLang Paradigm Gallery: Singles and Pairs

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"…

Designing Well-Behaved PatLang Programs

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…

PatLang Best Practices

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…

PatLang Capabilities & Honest Limitations

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…

PatLang Use Cases

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 Canonical PEG Grammar

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 Language Reference: Grammar & Syntax

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…

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…

PatLang Idioms & Patterns

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…

PatLang Numeric Tower

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…

Six Self-Hosted Dev Tools for PatLang

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…

PatLang IDE

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…

PatLang Live Playground

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…

PatLang Live REPL

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…

PatLang Patbuild

Driven by a manifest file ( self_hosting/patbuild.manifest ):

PatLang Compiler Self-Metrics

The self-hosted compiler front+middle end processing its own complete source (289918 chars), run under the Stage 0 interpreter while building this page:

PatLang Compiler Error Reasoning

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…

PatLang Branch Coverage

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…

PatLang All Paradigms Demo

Recursion, control flow, lists, events (when/emit), logic (fact/query), OO (new/send/get), and functional map/filter via apply .

PatLang Design by Contract

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 BDD Framework

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…

PatLang Inductive Synthesis: BDD to Code

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…

PatLang Goal-Oriented Programming

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 ... :- ...…

PatLang Declarative Rule Syntax

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.

PatLang Bitwise Operators & Bitfields

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.

PatLang Dynamic Syntax

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…

PatLang Ruby Transpilation

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…

PatLang Real OS Threads

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…

PatLang Fibers

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 )…

PatLang Robots: Cross-Thread Signaling Demo

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…

Presence, Discovery, and Non-Blocking Spawn

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 —…

PatLang Runtime Signals

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…

PatLang Virtual Filesystem

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 .

A Self-Orchestrated Microservices Demo in PatLang

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…

PatLang Durable Message Queue: Crash and Recovery

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…

PatLang Exemplar: Build Daemon

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…

PatLang Portfolio

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…

PatLang Hex RTS

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…

PatLang SQL Console

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) …

PatLang Family Tree

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…

PatLang Flow Graph Generator

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…

PatLang Flow Graphs

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 Browser GUI Generator

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…

PatLang Project Report Writer

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…

PatLang Project Report Simulator

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…

PatLang Maze

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…

PatLang Mandelbrot Set

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…

PatLang CGA Interval Classifier

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…

PatLang Self-Timing Benchmark

fib(27), a 2-million iteration loop, and a 200k-element vector build, each reporting its own elapsed milliseconds.

PatLang Point of Sale Demo

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.

PatLang Router DSL

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…

PatLang for Python Programmers

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…

PatLang for Java Programmers

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…

PatLang for C Programmers

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…

PatLang for Ruby Programmers

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…