I am working on family tree in prolog. I don't have any idea how to compile and run this program. Please give me some basic steps to run it.
-
Are you running Windows or Linux? Have you investigated any Prolog tools (via Google)? Have you read any tutorials? – lurker Oct 16 '13 at 10:33
5 Answers
Assuming you are using SWI-Prolog
Step 1: Put your dictionary into a text file. Here's an example dictionary:
dog(rover).
dog(felix).
dog(benny).
Step 2: Title your dictionary "something.pl" -- I called this one dogs.pl.
Step 3: Open up SWI-Prolog from the command line. In linux, I use the command swipl
at the command line. Once SWI-Prolog starts, you will see a command line that looks like ?-
Step 4: In SWI-Prolog, load your dictionary by using the consult
command like so:
?- consult('dogs.pl').
Step 5: Now that your dictionary is loaded, you can use it. Here's an example using our test dictionary about dogs:
?- dog(rover).
true.
dog(X).
X = rover ;
X = felix ;
X = benny .
That should pretty much do it as far as getting your prolog programs to load and run.
Finally, here's a link for how others run Prolog:
-
3
-
Can't you run prolog like a normal program? `swipl file.pl` and it's just like `python file.py`, or make a standalone prolog program somehow? Weirdd that the interactive session has to be used, and the user has to know what function they are meant to call from the file to get it to run. – theonlygusti Dec 17 '22 at 14:29
-
@theonlygusti I figured the questioner wanted to get into the REPL since that's usually where beginners like to use Prolog. Here are two questions on Stack that address your concerns: 1. [How to run SWI-Prolog from the command line?](https://stackoverflow.com/questions/25467090/how-to-run-swi-prolog-from-the-command-line) and 2. [How do I run Prolog from the command line and not drop into the REPL](https://stackoverflow.com/questions/58867730/how-do-i-run-a-prolog-file-from-the-command-line-and-not-drop-to-the-repl) – clay Dec 17 '22 at 15:48
When you have finished your code, do the following steps to run your code:
- Step 1: open your prolog terminal.(See pic1)
- Step 2: click "File" on the left of the top, then choose "Consult" to open the prolog file(your code file).(See pic2)
- Step 3: type in your function name and parameters.

- 471
- 5
- 5
Well, that would depend entirely on your Prolog implementation.
The language is one thing but how to compile or run your code is a different issue.
For example, Visual Prolog uses a key sequence within the IDE, CTRL-SHIFT-B, to build the code, or ALT-F5 to run the code. You need to find the equivalent way of doing the same thing in whatever Prolog implementation you're using (or at least let us know).

- 854,327
- 234
- 1,573
- 1,953
There's no official standard for the Prolog built-in predicates that compile and load a source file. The most common ones are consult(File)
, reconsult(File)
, and load_files(Files, Options)
. The shortcut [File| Files]
is also often available. You will need to consult the documentation of the Prolog system you're using. Be aware that even for the common ones above, the semantics often differ from system to system.

- 18,373
- 3
- 23
- 33
If you are using terminal or cmd
- Navigate to the folder where you saved your kB
- Run it as script using the following command
swipl -s file.pl
-
Please consider readability and use formatting when answering questions – Nanotron Feb 28 '22 at 11:27
-
What does `swipl -s file.pl` do ? Is it exactly the same as `swipl` then `consult('file.pl').` ? If so, then I don't think that counts as running as a script. It's more like loading a library. – theonlygusti Dec 17 '22 at 14:30