← the guideThe Systems Age

§ 02 — Eras · 1972

Prolog

state the facts, ask the question — logic, executable

Left: era context, features, and the 101 hello. Right: 3 core concepts, 3 deeper 201 lessons, the factorial specimen, and where Prolog lives today — each column scrolls on its own.

creators
Alain Colmerauer & Philippe Roussel, Marseille, 1972
status
niche · expert systems, parsing, constraint solving

The problem it solves

Natural-language questions and theorem-proving didn’t fit control flow. Prolog made logic itself executable: facts, rules, unification.

The problem it carries

The engine’s search is opaque, performance is a puzzle, and the fifth-generation hype wrote checks it couldn’t cash.

Key features

facts and rules
Knowledge, not procedures: relations stated as facts, and rules over those facts.
unification
Solving a goal means matching it against the database, substituting variables as it goes.
backtracking
Failure is not an error — the engine simply tries other ways; search is the control flow.
lists and recursion
A built-in relation over lists makes the language deeply expressive from the first day.

101 — hello, world

Session one is the smallest program that still counts as speaking Prolog: what every tutorial prints first, in the dialect that mattered when the language arrived (1972).

the first program1972
?- write('Hello, world'), nl.

101First contact — hello world and 3 ideas that define how Prolog reads. 201 — 3 lessons on mechanisms you meet after the factorial specimen: the sharp edges practitioners actually use.

101 — core concepts

3 fragments, each naming a habit of mind in Prolog. Read the note, then the code — together they are the 101 in one sitting.

01 — facts & rules

A program is a knowledge base: facts, and rules over facts.

man(socrates).
mortal(X) :- man(X).

02 — the query

You ask; Prolog searches and unifies to find the proof.

?- mortal(socrates).
   true.

03 — recursion over lists

Pattern matching IS the control flow — each clause is one case.

len([], 0).
len([_|T], N) :- len(T, M), N is M + 1.

201 — going deeper

The 201 assumes you have read the 101 and the specimen. Each lesson is one mechanism — what it is for, how it looks in code, and the trap or payoff that makes Prolog distinctive at scale.

  1. difference lists and accumulators
  2. cut and negation
  3. tabling and constraints

difference lists and accumulators

Naive list recursion is quadratic; the classic fix is a difference list with an accumulator — the same shape as a tail call in a functional language.

app([], Ys, Ys).
app([X|Xs], Ys, [X|Zs]) :- app(Xs, Ys, Zs).

cut and negation

The cut prunes the search space, and negation-as-failure turns failure into a goal — powerful, and a reliable source of “it works except when…” bugs.

parent(X, Y) :- mother(X, Y), !.   % commit to first solution
not_mother(X, Y) :- \+ mother(X, Y).

tabling and constraints

Memoized tables turn runaway recursion into a lookup, and CLP(FD) adds arithmetic constraints solved by propagation — the practical Prolog toolkit.

:- table f/2.
f(N, F) :- N > 0, F is N * F1, F1 = F(N-1).

The specimen — factorial

The rule: state the relation, ask the question — and the machine searches for its own proof. Logic itself, executable.

the rule1972
mortal(X) :- man(X).
man(socrates).

?- mortal(socrates).
   true.

Run it today

installbrew install swi-prolog

runswipl fact.pl

Where it is now

IBM’s Watson, code analyzers, scheduling and constraint systems — anywhere the problem is really search.