Getting started with Prolog
© 2004-2013 Jean-Marc Vanel - e-mail: Send your comments - My home page

  Last update

TOC

Your first Prolog session

There are numerous tutorials on Prolog on the Web, but they forget to tell indispensable howtos .

To start a Prolog interpreter on Linux (or cygwin ) enter;

swipl           # for SWI-Prolog 
yap             # for YaP
gprolog         # for GNU Prolog

To enter rules from the command line, type this :

[user].

This puts you in a mode where you can enter facts and rules. Otherwise you get this kind of message:

<>?- idiot(me).
ERROR: (user://2:121):
        Undefined procedure: idiot/1


You can then enter facts, e.g. :

father(me,sarah).

Or rules, e.g. :

father(X,Y) :- male(X), parent(X,Y).

After having entered the knowledge, type CONTROL-D to come back to the mode where you can enter goals (questions). Then you can ask:

| ?- father(me,X).
X = sarah
yes

To quit:

halt.

Using files

Create a file father.pl containing what we entered in the "enter facts and rules" mode. Then you can load this file under Prolog by typing this:

[father].

You can then enter goals like before.

Using the SWI Prolog IDE

This will start a Prolog editor on a new file, with realtime syntax highlight and check :

edit(file('father.pl')).

Paste this in the Prolog editor :

% facts:
male('Nat King Cole').
parent( 'Nat King Cole', 'Nathalie Cole').
father(me,sarah).
% rules :
father(X,Y) :- male(X), parent(X,Y).

Then select and click Compile / Compile buffer .

You can then ask queries in the command-line window :

?- father(X, Y).
X = me,
Y = sarah

Then type a semicolon (;) to get the next solution:

X = 'Nat King Cole',
Y = 'Nathalie Cole'.

?-

A dot (.) is printed, as it is the last solution, and the prompt re-appears.

Prolog links

Documentation / tutorials

The official prolog FAQ is a wonderful resource: http://www.logic.at/prolog/faq< wbr>/faq.html

Graph structures and paths, part of a real nice Prolog course entirely by examples, by J.R. Fisher, mentioned in:

Tutoral list in the Prolog FAQ

Learning Prolog (Univ. Saarland)

Electronic books by : Nilsson, Artificial Intelligence through Prolog by Neil C. Rowe ( can be found here and there on the Web)

Problems, code examples

P-99: Ninety-Nine Prolog Problems, by Werner Hett

The First 10 Prolog Programming Contests

code from book "the Art of Prolog"

Solutions to some exercises in "The Art of Prolog"

Prolog implementations

SWI-Prolog
Yap
XSB 
TuProlog , JLog ( in Java )
The GNU Prolog web site
SICStus Prolog User's Manual - Table of Contents
The links below need updating/review :
The Prolog Dictionary
Introduction to Prolog
Prolog Tutorials
Prolog Tutorial -- Contents
Prolog Tutorial
Prolog for Software Engineering
Free Online Prolog Tutorials (thefreecountry.com)
The Prolog language
Relational database programming
Introduction

http://www.cetus-links.org/oo_prolog.html

Blogs

http://www.cs.kuleuven.be/~toms/PlanetProlog/ - Tom Schrivers, one author of CHR
http://www.cs.kuleuven.be/~bmd/ - home page of Bart Demoen

Software

GNU Prolog GNU Prolog is a free implementation (under GPL) of the logic programming language PROLOG. It can compile to native machine code which is extremely fast in execution. Another feature is the included constraint solver.

XSB 

Logic Programming and Deductive Database system (Tabled Prolog) for Unix and Windows. 


The links below need updating/review :

 released files

77.23%

JLog - Prolog in Java 

JLog is a standard Prolog interpreter written in Java, so it runs almost anywhere. It is quite fast, and perfectly suited for educational purposes. It includes built-in source editor, query panels, online help, animation primitives, and a GUI debugger

JPL A set of Java classes and C functions providing a bridge between Java and Prolog
jsprolog An implementation of a Prolog inferencing engine in browser-friendly javascript.

????
PESS - Prolog Expert System Shell The Prolog Expert System Shell (PESS) is a software that generates ES using basically two components: Knowledge Base, used by the ES to guide its decisions making, and Inference Machine, cable of collection the rules and generating new facts.

Datalog Educational System 

The Datalog Educational System (DES) is a basic deductive database with Datalog as a query language developed for education. It can be used from most common Prolog interpreters and from executables (Windows and Unix/Linux). 

 released files

39.70%

Prolog+CG 

Prolog+CG is a Java implementation of Prolog with extensions implementing a subset of the Conceptual Graph (CG) theory of John Sowa. CGs are first-class datatypes on a par with terms. Object oriented extensions are also included. 

 released files

39.49%

PyProlog 

A Python extension embedding SWI-Prolog

 released files

18.45%

Object Oriented Prolog 

Oopl (rhymes with "scruple") is an object-oriented extension for Prolog. This kernel now lets you write Prolog programs making use of all the advantages of working with classes, instances, attributes and service-like predicates. 

Interfacing data sources with Prolog

Relational data sources

XML data sources

Interfacing GUI or Web applications with Prolog