SWI-Prolog

SWI-Prolog

Open source Prolog implementation and environment

Description

Rosters, timetable clashes, dependency resolution — written in an ordinary language these become nested loops and hand-rolled backtracking that nobody wants to touch a month later. Prolog flips it: you describe the rules and the constraints, and the solver does the searching. SWI-Prolog is the implementation that actually ships real programs — going since 1987, and not just a language but a full runtime you can build on, with over a million downloads by the project's own count.

It refuses to stay in the classroom. There is an HTTP server in the standard library, so reasoning logic goes straight out as a web service; JSON, XML and RDF are handled; threads are real threads; constraint libraries such as CLP(FD) come bundled; and a C interface bridges to whatever you already have. The interactive top-level makes the loop short: write a rule, ask a query, adjust, ask again.

Features



Interactive top-level: it starts as a REPL — consult a file and query it immediately, pressing semicolon to walk through solutions one at a time and see exactly what backtracking produced.

PceEmacs source editor: the built-in editor understands Prolog, highlighting syntax, jumping to predicate definitions and flagging undefined calls and singleton variables, with reload a keystroke away.

Graphical debugger: gtrace draws the execution, with breakpoints, stepping in and out, and the current bindings visible at each step — far easier than reading a textual trace when a search goes sideways.

Threads and profiling: genuine multithreading, plus an execution profiler that counts calls and time per predicate so bottlenecks are measured rather than guessed.

Constraint libraries: CLP(FD) and friends let you state that a set of variables must differ or sum to N as a constraint, so scheduling and puzzle problems need no hand-written pruning.

HTTP server and data formats: server and client libraries ship in the box alongside JSON, XML and RDF support, which is what turns an inference program into an API.

C and C++ interop: call C functions from Prolog, or embed SWI-Prolog inside a C program as a reasoning engine.

Cross-platform: official builds for Windows, macOS and the usual Linux distributions, with full source available, so code written in a lab runs at home unchanged.