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.
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:
When you have finished your code, do the following steps to run your code:
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).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With