Prolog
The logic programming language that pioneered declarative computing and artificial intelligence research
Created by Alain Colmerauer and Philippe Roussel
Prolog (Programming in Logic) is a logic programming language created in 1972 that fundamentally changed how we think about computation. Instead of telling the computer how to solve a problem step by step, you describe what the problem is, and Prolog figures out the solution.
History & Origins
Prolog was born from the intersection of computer science and linguistics. In 1972, Alain Colmerauer at the University of Aix-Marseille in France was working on natural language processing when he collaborated with logician Philippe Roussel and, later, with Robert Kowalski from Edinburgh. Their insight was revolutionary: formal logic could serve as a programming language.
The name “Prolog” was coined by Philippe Roussel as an abbreviation for “PROgrammation en LOGique” (French for “programming in logic”).
The Edinburgh Connection
While Prolog was born in Marseille, much of its development happened at the University of Edinburgh. David H.D. Warren created the first Prolog compiler and developed the Warren Abstract Machine (WAM), which became the standard for efficient Prolog implementation. Edinburgh Prolog syntax became the de facto standard and eventually the basis for ISO Prolog.
The Fifth Generation Project
Prolog gained enormous attention in the 1980s when Japan announced its Fifth Generation Computer Systems (FGCS) project, which aimed to create revolutionary AI systems using logic programming. While the project didn’t achieve all its ambitious goals, it spurred worldwide interest in Prolog and AI research.
Core Concepts
Facts and Rules
Prolog programs consist of facts (things that are true) and rules (relationships between facts):
| |
Queries
You interact with Prolog by asking queries:
| |
Unification
Prolog’s power comes from unification - the process of making two terms identical by finding appropriate variable bindings:
| |
Backtracking
When Prolog encounters a choice point, it can backtrack to try alternative solutions:
| |
Key Features
Declarative Programming
Prolog is declarative - you describe the problem, not the algorithm:
| |
Pattern Matching
Prolog excels at pattern matching on structured data:
| |
Built-in Search
Prolog has built-in depth-first search with backtracking:
| |
Constraint Logic Programming
Modern Prolog systems support constraint solving:
| |
Modern Implementations
SWI-Prolog
The most popular open-source Prolog:
- Full-featured development environment
- Excellent documentation
- Large library ecosystem
- Web frameworks (Pengines, SWISH)
- Active development since 1987
GNU Prolog
Free Prolog with native compilation:
- Compiles to native code
- Constraint solving built-in
- Strict ISO compliance
- Good for standalone applications
SICStus Prolog
Commercial Prolog for industrial applications:
- High performance
- Excellent constraint libraries
- Used in aviation, scheduling
- Professional support
Scryer Prolog
Modern Prolog written in Rust:
- ISO-compliant
- Focus on correctness
- Modern architecture
- Growing rapidly
Other Implementations
- YAP Prolog - High-performance, Prolog-to-C compiler
- XSB Prolog - Tabling (memoization) support
- ECLiPSe - Constraint programming focus
- B-Prolog - Tabling and action rules
- Tau Prolog - Prolog in JavaScript
Prolog Syntax Overview
Terms
Everything in Prolog is a term:
- Atoms:
hello,'Hello World',foo_bar - Numbers:
42,3.14,-17 - Variables:
X,Result,_Anonymous - Compound Terms:
foo(bar, baz),[1,2,3]
Lists
Lists are fundamental in Prolog:
| |
Operators
| |
Control Flow
| |
Classic Prolog Problems
Family Relationships
| |
List Operations
| |
Sorting
| |
Why Prolog Still Matters
Unique Problem-Solving Approach
Prolog forces you to think differently:
- Describe relationships, not procedures
- Let the computer search for solutions
- Handle multiple solutions naturally
AI and Knowledge Representation
Prolog remains valuable for:
- Expert systems
- Semantic web and ontologies
- Natural language processing
- Automated reasoning
Educational Value
Understanding Prolog helps you:
- Think about problems declaratively
- Understand pattern matching (used in ML, Haskell, Rust)
- Learn about search and backtracking
- Appreciate different programming paradigms
Modern Applications
- Type inference engines - Many type checkers use Prolog-like unification
- Database queries - SQL and Datalog share Prolog’s roots
- Configuration management - Complex constraint satisfaction
- Scheduling systems - Airlines, universities, factories
Learning Resources
Online
- SWI-Prolog Documentation - Comprehensive reference
- Learn Prolog Now! - Free online textbook
- SWISH - Browser-based Prolog environment
- The Power of Prolog - YouTube series by Markus Triska
Books
- The Art of Prolog by Sterling and Shapiro
- Programming in Prolog by Clocksin and Mellish
- Prolog Programming for Artificial Intelligence by Bratko
The Prolog Community
- SWI-Prolog Forum - Active discussion board
- comp.lang.prolog - Usenet newsgroup
- Prolog Association - Annual conferences
- Stack Overflow - Active prolog tag
Prolog’s Legacy
Prolog’s influence extends far beyond logic programming:
- Erlang was first implemented in Prolog
- Datalog is a subset of Prolog used in databases
- Pattern matching in modern languages follows Prolog’s lead
- Unification is used in type inference
- Constraint programming grew from Prolog extensions
Whether you use Prolog directly or not, understanding it will change how you think about programming. It’s a window into a fundamentally different way of computing - one where you describe the world and let the computer figure out the rest.
Timeline
Notable Uses & Legacy
IBM Watson
Early versions of IBM Watson used Prolog for knowledge representation and logical reasoning components.
Expert Systems
Prolog powered many 1980s expert systems including medical diagnosis (MYCIN derivatives) and configuration systems.
Natural Language Processing
Originally created for NLP, Prolog remains popular for computational linguistics and grammar parsing.
SICStus Prolog in Airlines
SICStus Prolog is used by major airlines for crew scheduling optimization and flight planning.
Formal Verification
Used in formal methods and theorem proving, including parts of the Coq proof assistant.
Erlang Origins
The Erlang programming language was originally implemented in Prolog before being rewritten in C.
Language Influence
Influenced By
Influenced
Running Today
Run examples using the official Docker image:
docker pull swipl:stableExample usage:
docker run --rm -v $(pwd):/app -w /app swipl:stable swipl -q hello.pl