Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Getting started with SWI-Prolog

Getting started with SWI-Prolog

Today (May 2017) I decided to learn a bit about Prolog. Here is how to start using it...

Install it on Ubuntu:

sudo apt-get install swi-prolog

Run it:

# or:

Run Prolog and load rules and facts from a file:

prolog -s test
# or:
prolog -s

Interactively add rules or facts:


% or:

("user" means add interactively instead of reading from a file.)

Load rules or facts from a file

% or the full filename:

Open the source file containing a given object in your default editor (e.g. Vim):


The file is automatically reloaded afterwards. To reload files that have been edited independently:


Run a query:


Press ; or spacebar after each result to see the next result. Press enter to stop looking for results. Press Ctrl-C then a to abort.

That's all for now. To actually learn the Prolog language, I'm currently reading Learn Prolog Now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment