DEV Community

Tomohiro Endo
Tomohiro Endo

Posted on • Edited on

Start Prolog with Docker

Prolog is a programming language that was born in 1972 and known as a logic programming language.

To run Prolog programs on your computer, using docker is the easiest way. It helps you set up and manage the environment.

Assuming that you already have docker installed, pull the SWI-Prolog Docker image by running the following command:

docker pull swipl
Enter fullscreen mode Exit fullscreen mode

and run a container

docker run --name swipl -it swipl /bin/bash
Enter fullscreen mode Exit fullscreen mode

After that in a docker container you started, create a Prolog code. For example:

likes(sam, lisa).
likes(sam, james).
likes(jiro, james).
Enter fullscreen mode Exit fullscreen mode

and save it as main.pl

And then load your Prolog code by running

swipl main.pl
Enter fullscreen mode Exit fullscreen mode

In the terminal, you will see a prompt like below

root@4d1dad014ee6:~# swipl main.pl
Welcome to SWI-Prolog (threaded, 64 bits, version 9.1.10)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.
Please run ?- license. for legal details.

For online help and background, visit https://www.swi-prolog.org
For built-in help, use ?- help(Topic). or ?- apropos(Word).

?- 
Enter fullscreen mode Exit fullscreen mode

You can now type Prolog queries at the prompt and receive answers. For example, try:

?- likes(X, lisa).
Enter fullscreen mode Exit fullscreen mode

The Prolog interpreter will provide the answer:

X = sam.
Enter fullscreen mode Exit fullscreen mode

Enjoy exploring Prolog!

Top comments (0)