Running The Prolog Interpreter On Solaris Unix

The interpreter is called cprolog and it is located in /opt/cprolog-1.5/bin/ on the open-lab machines. You can add that to your path file by modifying your .cshrc file to contain the following command at the end

module load cprolog/1.5

You must source your .cshrc file for this change to take effect.

source .cshrc

Note next time you log in, it will be in your path automatically because .cshrc is read each time you start up a command shell (and that happens when you log in).

You can run the interpreter with the following command:

cprolog

You will see the following prompt:

C-Prolog version 1.5
| ?- 

The | ?- is the query prompt. You may enter any Prolog query followed by a period and the interpreter will read it, try to solve it, then print yes, or no, or variable bindings that will make it yes.

You can load a file of definitions with the following command:

consult(file).

Or with the command

[file1, file2].

Where file1 and file2 are the names of your files to load (located in the current working directory). You should give Prolog files no extension so it will be easier to give their names as atoms.

When you make an error, the interpreter will try to let you know, but it doesn't drop you into a break/debug package like the Lisp interpreter does.

Note if you consult a file a second time, it will just add the rules again to the relation. You should reconsult to reload a file so that the former definitions are replaced by the new ones.

| ?- reconsult(myfile).

You can leave the Prolog interpreter by typing a control D.

^D

You can trace the evaluation of your functions by spying on them:

| ?- spy(myRelation).

You can print out the definition of a relation from within Prolog with listing, e.g,

listing(father).