CSE 341 Lecture Notes - Running CLP(R)

We're going to first study Prolog, and then CLP(R).

CLP(R) stands for "Constraint Logic Programming for the real numbers". CLP(R) is almost a superset of Prolog, and everything in Sethi's description of Prolog in Chapter 11 will also work in CLP(R), except for arithmetic (bottom of page 437). So we'll just use CLP(R) to run all our programs.

Arithmetic in CLP(R) is much more interesting than in Prolog, and we'll get to it presently.

To run CLP(R) on orcas or sanjuan:

The executable file is /cse/courses/misc_lang/axp/clpr/bin/clpr

To access this easily, add the following line to your .cshrc file:

set path = ($path /cse/courses/misc_lang/axp/clpr/bin)
Or modify your set path=... entry appropriately if you already have one. Then you can invoke the system by just typing
clpr
(Why is Miranda automatically in your search path and clpr not? I don't know.)

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

You can type a query to it, for example X=[1,2,3], Y=100. 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 Miranda, Prolog and CLP(R) have separate query and definition modes. To define some rules, put them in a file, say "mystuff". Then load them into CLP(R) using the goal consult("mystuff").

You can set up a second window to edit the file mystuff. To reload all the definitions after you've edited, use the goal reconsult("mystuff").

Or (naturally) you can run the whole thing under emacs. Start up emacs, then type <esc>x shell, then type clpr.

Arithmetic

For now, all you need to know is that = does the right thing for arithmetic in CLP(R). For example:
?- X=Y+2, Y=5.

X = 7
Y = 5

*** Yes
Or more interestingly:
?- 2*X+Y=10, X+Y=20.

X = -10
Y = 30

*** Yes