Running Prolog at UMBC
We have Sicstus Prolog installed on the gl machines as well as the CSEE machines.
Invoking Prolog
You can invoke the Prolog interpreter from the Unix command line using the command "sicstus". Alternatively, you may prefer to run Prolog from within Emacs. See the section in the sicstus prolog manual on How to Run Prolog.
Here is a simple session. We'll start by cd'ing to the directory where we have our prolog code and invoke sicsus, which prints a hearld.
[5:35pm] linuxserver1 156(~)=>cd prolog [5:35pm] linuxserver1 157(~/prolog)=>ls kinship.pl myfamily.pl [5:35pm] linuxserver1 158(~/prolog)=>sicstus SICStus 3.7.1 (Linux-2.2.5-15-i686): Wed Aug 11 16:30:39 CEST 1999 Licensed to umbc.edu
Next we will load or consult the two files, kinship.pl and myfamily.pl. Note that (i) the prompt is "| ?-" which indicates that prolog is expecting a query term. (ii) entering "[foo]" is special syntax that "consults" the file foo.pl. Consulting a file of terms reads in each term and asserts it into the database. This is how you add facts and rules to the database.
Now we will enster some queries and see what comes back. After computing an answer, Prolog shows the values for the variables and waits for user input. Entering a return indicates that you do not want any more answers. Entering a semicolon means that you want prolog to backtrack and to try to find anyother solution.| ?- [kinship]. {consulting /home/faculty4/finin/prolog/kinship.pl...} {/home/faculty4/finin/prolog/kinship.pl consulted, 0 msec 752 bytes} yes | ?- [myfamily]. {consulting /home/faculty4/finin/prolog/myfamily.pl...} {/home/faculty4/finin/prolog/myfamily.pl consulted, 0 msec 1424 bytes} yes
| ?- parent(tim,X). X = peter ? ; X = katherine ? ; X = clare ? ; no | ?- parent(tim,X),male(X). X = peter ? ; no
Now we'll try entering a predicate that is not defined -- i.e., there is no fact or rule about a two argument grandfather relations. prolog prints an error message and gives us a new prompt
| ?- grandfather(X,Y). {EXISTENCE ERROR: grandfather(_35,_36): procedure user:grandfather/2 does not exist}
Here are some more queries.
| ?- grandparent(X,Y). X = tom, Y = peter ? ; X = tom, Y = katherine ? ; X = tom, Y = clare ? ; no | ?-