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, and PatLang has some capabilities Python doesn't. This page is a fast map from what you already know to what's actually here.

The quick mental model

PatLang reads like a wordier Python with Ruby-flavoured keywords (make a function called, end) and an exact numeric tower instead of Python's float-heavy arithmetic. Where Python leans on duck typing and dunder methods for its object model, PatLang's object model is four plain host functions (new/get/set_var/send) with no class hierarchy at all. And where Python's standard library is enormous, PatLang's "less usual" strength is a small set of genuinely-implemented paradigms — real logic programming, real goal-oriented planning, real runtime signals — that Python only gets via third-party libraries, if at all.

Syntax, side by side

# Python
def add(a, b):
    return a + b

x = 5
if x > 0:
    print("positive")
elif x < 0:
    print("negative")
else:
    print("zero")

i = 0
while i < 10:
    i += 1
# PatLang
make a function called add takes a, b returns sum
  return a + b
end

let x = 5
if x > 0 then
  print("positive")
elif x < 0 then
  print("negative")
else
  print("zero")
end

let i = 0
while i < 10 do
  let i = i + 1
end

Bindings are explicit: let for a fresh (or reassigned) binding, let mut where the grammar wants you to be explicit about intending to reassign a name later in a block — see the Grammar reference for the exact rule, since it's slightly stricter than Python's "just assign it" model.

Things Python has that PatLang doesn't

  • No for loop at all — only while. There's no for x in xs:, no range()-driven loop, no list/dict comprehension. You write the counter yourself.
  • No break/continue — genuinely absent from the grammar, not just discouraged. Structure loops with a condition flag instead of expecting to jump out of them early.
  • No f-strings or any string interpolation. Strings are double-quoted only, with \n \t \r \" \\ escapes; build dynamic strings with + concatenation.
  • No classes, no inheritance, no dunder methods, no decorators. See the object model section below — it's a genuinely different way of getting mutable named state, not a class system with the syntax filed off.
  • No exceptions, no try/except. A host-function error (a failed tcp_connect, a bad file path) is fatal to the whole program — there's no way to catch and recover from it. Design around failure rather than handling it after the fact.
  • No hex/octal/binary/scientific-notation number literals, no underscore-separated digits. Just plain decimal digits and an optional single decimal point.

Objects without classes

Python's object model is classes, instances, and method resolution order. PatLang's is four host functions operating on a shared, string-keyed store — genuinely no class keyword in the grammar at all:

let acct = new("Account")
set_var(acct, "balance", 100)
send(acct, "deposit", [50])
print(get(acct, "balance"))

There's no inheritance, no method dispatch beyond a single built-in "set" verb, and no privacy. If you're used to reaching for a class the moment you have more than one related piece of state, get comfortable reaching for this instead — see the Paradigms Guide's OO section.

Numbers behave differently — on purpose

Python 3's / always produces a float, and large integers silently become arbitrary-precision automatically. PatLang goes further, and more precisely: 7 / 2 is the exact fraction 7/2 (a Rational), not 3.5 and not 3 — the single most common surprise for anyone arriving with C-family or even Python intuitions about division. Integer overflow promotes to BigInt automatically (matching Python's own big-int behaviour), and sqrt of a negative number promotes to Complex rather than raising. There is no literal syntax for any of these — you always write plain digits, and the runtime promotes as needed. See the Numeric Tower section.

What PatLang has that Python doesn't (without a library)

  • Real logic programming, built in. rule_add/solve is genuine SLD-style backward-chaining resolution with backtracking — Prolog-shaped reasoning as a first-class part of the language, not a third-party constraint solver.
  • Real goal-oriented action planning (GOAP). action_add/plan does uniform-cost forward search over actions with preconditions/effects/cost, finding a genuinely cheapest plan — the same technique game AI uses for NPC decision-making, available as two function calls.
  • Runtime signals with no external message broker. A running PatLang program can receive a named signal from a second CLI invocation or a local network call, dispatched through the same event mechanism as everything else — see the signals demo.
  • A self-hosting compiler you can actually read. PatLang's own compiler is written in PatLang and compiles itself; Python's CPython is a large C codebase most Python programmers never look at.
  • Real threads, not just Python's GIL-limited threading or a separate multiprocessing module. parallel_map spawns genuine OS threads with true parallelism.

See the build daemon exemplar for several of these working together in one real program, and the journey page for how they got built.

See also

Grammar & Syntax for the full, precise rules. Paradigms Guide for depth on every capability mentioned above. Idioms & Patterns for real gotchas found while building PatLang itself. If you know another language too, see PatLang for Ruby Programmers, PatLang for Java Programmers, or PatLang for C Programmers.