CSE 341 Lecture Notes - Running CLP(R)

To run CLP(R) on attu type

clpr
The system is interactive, like Scheme and Haskell. The system prompt is
?-

You can type a query to it, for example X=[42,Y], Y=1. Here's a transcript of this:

CLP(R) Version 1.2
(c) Copyright International Business Machines Corporation
1989 (1991, 1992) All Rights Reserved

1 ?- X=[42,Y], Y=1.

X = [42, 1]
Y = 1

*** Yes

Like Haskell, CLP(R) has separate query and definition modes. To define some rules, put them in a file, say "mystuff.clpr". Then load them into CLP(R) using the goal consult("mystuff.clpr").

Type control-d to exit clpr.

CLP(R) isn't integrated with an editor -- just use emacs (or another editor if you prefer) to edit the file with the rules. If you are debugging away, our suggested approach is to open two terminal windows: one with CLP(R), the second with emacs and your file. When you are in CLP(R), you can reload all the definitions after you've made an edit using the goal reconsult("mystuff"). Or exit and restart it.

Emacs fans may prefer to run the whole thing under emacs. To do this, start up emacs on the file with your rules. Then split your window into two buffers using control-x 2. Continue editing your file in one of the buffers. In the other buffer type <esc>x shell to get a unix shell, then type clpr.

Shortcuts

For the consult command, the system will try the extension .clpr if you don't give one explicitly. You can omit the quotes around the file name if you don't include an extension. To read in a file mystuff.clpr, you can type
[mystuff].
rather than
consult("mystuff").
or
consult("mystuff.clpr").

Debugging

The debugging facilities in CLP(R) are, in the words of the manual, 'rudimentary'. See Section 4.9 of the manual for a description.

For example, suppose you have a file append.clpr, and that you want to trace all goals. Do the following to set up debugging and to trace the goal append(A,B,[1,2]):

attu% clpr
?- codegen_debug.
?- [append].
?- spy.
?- trace.
?- append(A,B,[1,2]).