Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run prolog code?

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.

like image 806
Subodh Mankar Avatar asked Oct 16 '13 08:10

Subodh Mankar


4 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:

  1. Adventures in Prolog
like image 92
clay Avatar answered Oct 26 '22 05:10

clay


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.

Step 1: open the prolog terminal

Step 2: click "File" on the left of the top, then choose "Consult" to open the prolog file

like image 28
SuperGuy10 Avatar answered Oct 26 '22 03:10

SuperGuy10


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).

like image 1
paxdiablo Avatar answered Oct 26 '22 03:10

paxdiablo


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.

like image 1
Paulo Moura Avatar answered Oct 26 '22 04:10

Paulo Moura