PatLang for Python Programmers
For new readers
This page assumes you already know Python and maps that knowledge onto PatLang by contrast. If Python isn't your background, the Paradigms Guide is a better starting point.
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 an optional class keyword layered on top for single inheritance and composable traits (see below) — much thinner than Python's, no dunder methods or multiple inheritance. 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
forloop at all — onlywhile. There's nofor x in xs:, norange()-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. - Classes and single inheritance exist now, but no dunder methods, no decorators, no multiple inheritance. See the object model section below — composable traits fill some of the same role a mixin base class would in Python, but there's still no
__init__/__str__-style special-method protocol. - No exceptions, no
try/except. A host-function error (a failedtcp_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, a lighter class system
Underneath, every object is still four host functions operating on a shared, string-keyed store:
let acct = new("Account")
set_var(acct, "balance", 100)
send(acct, "deposit", [50])
print(get(acct, "balance"))
There's also a real class keyword now, with single inheritance and composable traits (last-listed one wins on a collision) — no full C3 linearization like Python's own multiple inheritance, but a single explicit chain plus named, ordered mixins covers a lot of the same ground:
# Python's class Animal: ... / class Person(Animal): ... becomes:
class Animal {
field legs = 4
}
class Person inherits Animal {
field legs = 2
}
let p = new("Person", "p1")
print(get(p, "legs")) # 2
Method resolution order is simpler than Python's: own class, then traits (last-listed wins), then the parent chain — no diamond-inheritance ambiguity to resolve, because there's only one parent. Still no privacy and no dunder-method protocol. If you're used to reaching for a class the moment you have more than one related piece of state, that instinct now works directly — see the Paradigms Guide's OO section for the full syntax.
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/solveis 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/plandoes 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
multiprocessingmodule.parallel_mapspawns 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.