Unlike many programming languages, ** Prolog** does not automatically evaluate
`expressions'. For example, in Pascal,

the termY := 2 + 1;

with the consequence that the termY = 2 + 1.

Similar problems arise in relation to LISP. LISP will generally seek to evaluate expressions. For example, inLISP evaluates the term (s-expression)(foo (+ 1 2) 3)

(foo (+ 1 2) 3)by evaluating(+ 1 2)to3and then evaluating(foo 3 3). A naive attempt to construct a similar expression inPrologmight look like:butfoo(1+2,3)

Prologdoesnottry to evaluate the term1+2.

Of course, there are times when evaluation is exactly
what is wanted. Sometimes, particularly with arithmetic expressions,
we want to evaluate them.
A special predicate ** is/2** is provided.
This predicate can be used as in:

In this case, the termY is 2 + 1.

We can use ** is/2** to implement a successor relation:

where it is intended thatsuccessor(X,Y):-Y is X + 1.

In the above, note that
** X + 1 **
is intended to be
* evaluated*.

This means that you must use the stated calling pattern
as to try to solve the goal ** successor(X,7)** will lead
to trying to evaluate ** X + 1** with ** X**
* unbound*. This cannot be done. The result is an error message and
the goal fails.

Consider the queryThis results in a failure and an error message.?-3 is X+1.

Yet the logical statement that we might associate with the query is*** Error: uninstantiated variable in arithmetic expression:

This requires that we can search for the integer that, when added to 1 gives 3. Quite reasonable, but the arithmetic evaluator used is non-reversible. So the evaluation of arithmetic expressions is a one-way process.X 3 is_one_more_than X

Therefore
** is/2**
must always be called with its second argument as an arithmetic
expression which has any variables already bound.
So ** successor/2** is not `reversible'. For these queries,

Mon May 24 20:14:48 BST 1999