Est. 1999 Intermediate

GNU Prolog

A free, ISO-standard Prolog compiler with native code generation and a built-in finite-domain constraint solver

Created by Daniel Diaz

Paradigm Logic programming, Constraint logic programming, Declarative
Typing Dynamic, Untyped (terms)
First Appeared 1999
Latest Version GNU Prolog 1.5.0 (released around 2021)

GNU Prolog (often abbreviated as gprolog) is a free Prolog compiler developed primarily by Daniel Diaz. It is notable for compiling Prolog programs to native machine code, for shipping a built-in finite-domain (FD) constraint solver, and for closely tracking the ISO Prolog standard. Distributed as part of the GNU Project under the GNU General Public License, it has been a staple of logic programming education and research since its first public release around 1999.

History & Origins

GNU Prolog grew out of Daniel Diaz’s earlier work on wamcc, a Prolog-to-C compiler released in the mid-1990s while Diaz was working at INRIA and later at the University of Paris. wamcc demonstrated that Prolog could be compiled to efficient native code by translating the Warren Abstract Machine (WAM) instructions into C, but the approach inherited the slow compile times typical of large generated C programs.

To address this, Diaz designed a new compilation scheme based on a small, portable mini-assembly intermediate language. The mini-assembler could be translated to the native assembly language of each supported platform, giving fast compilation and direct native execution. This new compiler, together with a runtime library and a finite-domain constraint solver derived from Diaz’s earlier clp(FD) work with Philippe Codognet, became GNU Prolog.

The first public version was released in 1999. The system was documented in detail in the 2002 paper “Design and Implementation of the GNU Prolog System” by Diaz and Codognet, which remains the canonical technical reference.

Design Philosophy

GNU Prolog’s design centers on three goals:

  1. Free and standard. It implements the ISO Prolog standard (ISO/IEC 13211-1) and most of its corrigenda, providing the standard’s built-in predicates, error system, and syntax under the GPL.
  2. Native compilation. Programs are compiled to native machine code via a portable mini-assembler, producing standalone executables without requiring a Prolog interpreter at runtime.
  3. Built-in constraints. A finite-domain constraint solver is part of the core distribution, not an optional add-on, reflecting Diaz’s long-standing interest in constraint logic programming.

Key Features

Compilation to Native Code

GNU Prolog compiles each Prolog source file through several stages: Prolog → WAM → mini-assembler → platform-specific assembly → object code. The result can be linked into a standalone executable that does not depend on a separate Prolog runtime image at execution time. This is unusual among Prolog systems, most of which use a bytecode interpreter or save a complete heap image.

Finite-Domain Constraint Solver

The built-in FD solver supports constraint logic programming over integers with operators such as #=, #\=, #<, #>, #=<, and #>=, along with labeling strategies for enumerating solutions:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
:- use_module(library(clpfd)).

send_more_money(Letters) :-
    Letters = [S,E,N,D,M,O,R,Y],
    Letters ins 0..9,
    all_different(Letters),
    S #\= 0, M #\= 0,
                1000*S + 100*E + 10*N + D
    +           1000*M + 100*O + 10*R + E
    #= 10000*M + 1000*O + 100*N + 10*E + Y,
    labeling([], Letters).

ISO Compliance

GNU Prolog implements the predicates, directives, error terms, and stream I/O model defined by ISO/IEC 13211-1, which makes it useful as a practical conformance reference when porting code between Prolog systems.

Interactive Top-Level and Debugger

In addition to its compiler, GNU Prolog ships an interactive top-level interpreter and a four-port debugger (call, exit, redo, fail) following the Byrd box model familiar from other Prolog systems.

Foreign Function Interface

A C-level FFI allows Prolog code to call C functions and vice versa, which is particularly useful when embedding GNU Prolog logic into larger native applications.

Example: A Small Program

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
% facts
parent(tom, bob).
parent(tom, liz).
parent(bob, ann).

% rule
grandparent(X, Z) :-
    parent(X, Y),
    parent(Y, Z).

?- grandparent(tom, Who).
Who = ann.

This program can be loaded interactively with gprolog or compiled to a native executable with gplc family.pl, producing a binary that can be invoked directly.

Evolution

Releases of GNU Prolog have been relatively infrequent and primarily driven by Daniel Diaz, with contributions from the wider GNU community. Major version lines have focused on:

  • Expanding ISO conformance, including corrigenda to the standard.
  • Porting the mini-assembler back-end to additional CPU architectures and operating systems.
  • Maintaining the FD constraint solver and refining its labeling strategies.
  • Build-system modernization to handle changes in macOS, Linux, and Windows toolchains.

The 1.5.0 release, around 2021, broadened 64-bit platform support and updated portions of the runtime; specific dates for individual point releases should be verified against the official GNU Prolog manual and release notes.

Current Relevance

GNU Prolog remains in active use, particularly in:

  • Education — its free license and conformance to ISO Prolog make it a popular choice for university courses.
  • Constraint programming research — the built-in FD solver provides a convenient laboratory for experimenting with propagation and search.
  • Embedded logic components — its native-code output and C FFI make it well suited to embedding Prolog reasoning inside larger native applications.

It is not the dominant general-purpose Prolog today — that role is widely held by SWI-Prolog — but GNU Prolog occupies a distinct niche thanks to its compilation model and standards focus.

Why It Matters

GNU Prolog is significant for several reasons:

  • It is one of the few mainstream Prolog systems to compile to native machine code via an explicit, portable mini-assembler.
  • It bundles constraint logic programming over finite domains as a first-class feature.
  • It is a faithful and freely available implementation of the ISO Prolog standard, which has made it a long-running reference point for the logic programming community.

For anyone studying compiler design, constraint programming, or the practical realization of the Warren Abstract Machine, GNU Prolog is a compact and well-documented system worth examining.

Learning Resources

  • GNU Prolog Manual — the official reference, covering language, built-ins, debugger, and FD solver.
  • “Design and Implementation of the GNU Prolog System” by Daniel Diaz and Philippe Codognet (2002) — the canonical paper on the system’s architecture.
  • The Art of Prolog by Sterling and Shapiro — a general Prolog text whose programs run cleanly on GNU Prolog.
  • Programming in Prolog by Clocksin and Mellish — a classic introduction to standard Prolog.

Timeline

1995
Daniel Diaz releases wamcc, a Prolog-to-C compiler that serves as the technical predecessor of GNU Prolog
1996
Development of GNU Prolog begins, with Daniel Diaz designing a new compilation scheme based on a mini-assembly intermediate language
1999
First public release of GNU Prolog (version 1.0) as part of the GNU Project
2002
Diaz and Codognet publish 'Design and Implementation of the GNU Prolog System' describing the compiler architecture and FD constraint solver
2007
Version 1.3.0 released with improvements to the constraint solver and ISO conformance
2013
Version 1.4.4 released, with continued ISO Prolog compliance work and 64-bit platform support
2016
Version 1.4.5 released (approximately mid-2016) with Mac OS X compatibility fixes and Windows build improvements
2021
Version 1.5.0 released, including updates to the underlying runtime and broader 64-bit platform support

Notable Uses & Legacy

University teaching

Widely adopted in university courses on logic programming and artificial intelligence due to its free availability, strict ISO Prolog conformance, and simple installation.

Constraint satisfaction research

Used in academic research on finite-domain constraint programming, where its built-in FD solver provides an accessible platform for experimenting with constraint propagation and labeling strategies.

Standalone executables

Favored for projects that need to ship Prolog logic as standalone native binaries, since GNU Prolog compiles programs to native machine code rather than relying on an interpreter.

ISO Prolog reference implementation

Used as a practical reference for the ISO/IEC 13211-1 Prolog standard, since the implementation closely tracks the standard's built-in predicates and error system.

Language Influence

Influenced By

Prolog wamcc Warren Abstract Machine ISO Prolog

Running Today

Run examples using the official Docker image:

docker pull
Last updated: