How to run prolog code?

Subodh Mankar picture Subodh Mankar · Oct 16, 2013 · Viewed 72.6k times · Source

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.

Answer

clay picture clay · Oct 16, 2013

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:

  1. Adventures in Prolog