Tips on Using Prolog

 

There are two versions of prolog available on the MSCC machines. One is the teletype version which is invoked by typing "prolog" at the prompt on entropy.ms (Well, I tried to use rsh, but it seems like it is not working for prolog.) This version can be run anywhere (any telnet window.) I myself have not used it very much. The best way to learn how to use it is by typing "man prolog" when you are on entropy.ms. If you are on other ms machines, type "rsh entropy man prolog" to do a remote command, because the documents (as well as the software itself) are only available on entropy; The other version is "qui, " which is for x termianls. You need to be on an x-termial to use it (e.g. the non-Macs in the MSCC lab.) To use it, you need to set your display variable to point to your current screen. For example, if your terminal is called squid, on mscc type: setenv DISPLAY squid:0.0, then type "qui".

 

NOTE: the info for "qui" is from my old experience, but now it seems it’s not quite working. I tried to use it on the x-terms recently in Sieg hall, but it’s just kinda doing nothing, although the process does exist. You can tried to use it directly on the MSCC x-terms and verify the usablity of it.

 

The two versions are basically used the same way.

The X terminal version has a graphical interface and a nice debugger, selectable from the menu bar. If you are running the version of Prolog with the teletype interface (by giving the command 'prolog') you can still use the debugger, although it isn't as nice as the X version.

 

Queries

 

Queries are of the form:

 

predicate( ... ).

 

NOTE: The predicate and parenthesis can not be separated by any white space. The query can be several lines long and is terminated with a period.

 

*Predicates the Hard Way

 

To manually enter predicates or clauses use the following form:

 

assert( -term- ).

e.g. assert(eat(a,b)).

 

*Predicates the Easy Way

 

To load predicates from a file, make a file such as ~/cse413/test.pl

Then in Prolog enter the following statement:

 

consult('~/cse413/test.pl').

 

NOTE: the path name can be relative to your current directory.

 

*Results to Queries

• Press ';' for the next result.

• Hit enter if you want to stop unifying results.

 

 

Debugger stuffs:

To trace: give the goal

trace.

 

To stop tracing:  

untrace.

 

To spy on a particular rule named my_rule:

spy(my_rule).

 

To turn off spying on one rule:

nospy(my_rule).

 

To turn off all spying:

nospyall.

 

When you get to the trace, typing carriage return will 'creep' (in other words, show everything). Typing ? will give you a list of all the commands.

Also there is an extensive online manual. Give the command:

 

manual.

 

for the top-level menu. For help on a particular topic (e.g. trace) try

 

manual(trace).

 

This may give you some subsection references -- in this case

 

Quintus Prolog Help System

 

1 - trace {manual(f-1)} 2 - trace mode {manual(e-1-4-1)} 3 - trace/0 -- built-in predicate {manual(i-2-2)} 4 - trace/0 -- reference page: {manual(l-3-178)}

 

Generally, the reference page is the best place to look at, so in this case give the goal

 

manual(l-3-178).

 

and it will tell you all about trace.

 

Finally, to get a log of your work when handing in your homework, from the teletype version you can use the unix "script" command to keep a log file (explained below.) There is a log option in the X version of Prolog; however, I couldn't get it to work right. If nothing else you can sweep over the items of interest in the Prolog window, then paste this into an editor in another window. Or get everything working in the X version and then use "script" with the teletype version.

 

To make a script:

 

> script filename

> prolog

> .....

> ..... (load your program and test here)

> exit

 

The scriptfile will be filename. If you forget to supply a filename, the scriptfile will be of name typescript.

 

 

 

 

 


Kitman Ho - University of Washington CS&E Department
Email: kitman@cs.washington.edu
WWW: http://www.cs.washington.edu/homes/kitman