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
[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

Next we will load or consult the two files, and 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 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.

| ?- [kinship].
{consulting /home/faculty4/finin/prolog/}
{/home/faculty4/finin/prolog/ consulted, 0 msec 752 bytes}

| ?- [myfamily].
{consulting /home/faculty4/finin/prolog/}
{/home/faculty4/finin/prolog/ consulted, 0 msec 1424 bytes}


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.
| ?- parent(tim,X).

X = peter ? ;

X = katherine ? ;

X = clare ? ;

| ?- parent(tim,X),male(X).

X = peter ? ;


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 ? ;

| ?-