Previous Up Next

18.3  Suspending Built-Ins and the Suspend-Library

Basic ECLiPSe has two built-in predicates whose behaviour includes suspending: the sound negation built-in /1 and the sound disequality predicate =/2. Instead of succeeding or failing, they will suspend when their arguments are insufficiently instantiated to make a decision. For example

?- X ~= 3.
X = X
There is 1 delayed goal.
Yes (0.00s cpu)

Here, the system does not have enough information to decide whether the query is true or false. The goal remains delayed and we have a case of floundering (the ECLiPSe toplevel indicates this situation by printing a message about delayed goals at the end of the computation).

However, when the variable which was responsible for the suspension gets instantiated later, the delayed goal will be resumed (woken) and either succeed, fail, or suspend again. In the following example, the disequality predicate initially suspends, but wakes up later and succeeds or fails, respectively:

?- X ~= 3, X = 4.
X = 4
Yes (0.00s cpu)
?- X ~= 3, X = 3.
No (0.00s cpu)

Further predicate implementations with the same behaviour (delay until all arguments are ground) can be found in the suspend library lib(suspend). In particular, it implements all common arithmetic predicates plus the constraints defined by the Common Arithmetic Solver Interface (see Constraint Library Manual), for instance

=:=/2, =\=/2,  >=/2,  =</2,  >/2,  </2,
 $=/2, $\=/2, $>=/2, $=</2, $>/2, $</2,
 #=/2, #\=/2, #>=/2, #=</2, #>/2, #</2,
integers/1, reals/1

The solver will suspend these predicates until all their arguments are ground.1

The suspend library is loaded into ECLiPSe on start-up, but the constraints associated with the suspend solver are not imported. To use them, either import the suspend library to the current module, or call the constraint qualified with the module:

suspend:(X > 2), suspend:(X #=< 5)

1
Note that more powerful versions of these constraints exist in other solvers such as the interval solver lib(ic).

Previous Up Next