Language
Prolog
- First appeared
- 1972
- Paradigm
- Logic programming, declarative
- Toolchain
- SWI-Prolog 9.2.9
- Container image
debian:trixie-20261027-slim + swi-prolog-core 9.2.9
Prolog (PROgrammation en LOGique) was created in Marseille in 1972 for working with natural language, and it became the other great language of early artificial intelligence, beside Lisp. Japan’s Fifth Generation Computer project of the 1980s was built around logic programming. Today it’s used in rule engines, type checkers, and parts of IBM’s Watson.
A Prolog program is a set of facts and rules. You don’t tell it what to
do next; you ask a question, and it searches for values that make the
question true, backing up to try another choice whenever a goal fails.
There are no loops and no assignment: a variable gets one value per
attempt, and repetition is recursion or helpers such as maplist and
findall. The implementations use SWI-Prolog’s built-ins and the
libraries that ship with it, which have lists, strings, and sorting, but
no statistics. Add-on packs aren’t installed.
Quirks
X = 1 + 2makesXthe term1+2, not 3. OnlyX is 1 + 2evaluates.sortremoves repeated values:sort([3,1,2,1,3], S)gives[1,2,3].msortkeeps them, giving[1,1,2,3,3].- A goal that can’t be satisfied simply fails, with no error. If
mainfails, all you see ismain: false. 4 / 2is the integer 2, but7 / 2is 3.5.-7 // 2is −3, and-7 div 2is −4."rosa"is a string androsais an atom, and they aren’t equal.- The run script stops on any warning, such as a variable used only once, which is usually a typo.
Concepts in Prolog
- Cross-validation
- Decision tree
- Descriptive statistics
- k-means clustering
- k-nearest neighbors
- Linear regression
- Logistic regression
- Naive Bayes
- Principal component analysis
Run the examples locally
You need Docker and Python 3. The harness builds the pinned container and runs every Prolog example:
git clone https://github.com/qnixon/dswithx.git
cd dswithx
python3 harness/run_tests.py --language prolog