next up previous contents index
Next: Primitives on suspending variables Up: Delaying Previous: Delay clauses   Contents   Index

Implementing freeze by using delay clauses

Delay clauses defined here are much more powerful than other delay constructs available in different Prolog systems. They extend delay clauses proposed by Micha Meier which are unable to describe triggers and actions. All other constructs, such as freeze in Prolog-II and when declarations in NU-Prolog, can be implemented very easily by using delay clauses. This section shows how to implement freeze by using delay clauses.

The goal freeze(X,Goal) is equivalent semantically to Goal, but its evaluation will be delayed until X becomes a nonvariable term. The following predicate defines freeze/2:


    delay freeze(X,Goal):-var(X) : {ins(X)}.
    freeze(X,Goal):-true : call(Goal).
As another example, consider the goal:

    freeze(X,freeze(Y,q(X,Y)))
This goal is equivalent to p(X,Y), which is defined as follows:

    delay p(X,Y):-var(X) : {ins(X)}.
    delay p(X,Y):-var(Y) : {ins(Y)}.
    p(X,Y):-true : q(X,Y).
A predicate call p(X,Y) will be delayed when either X or Y is a variable.

The following describes a delay condition that is difficult to describe by using freeze:


    delay p(X,Y):-var(X),var(Y) : {ins(X),ins(Y)}.
    p(X,Y):-true : q(X,Y).
A predicate call p(X,Y) will be delayed when both X and Y are variables.

In the example programs shown above, no delay clause contains actions and all triggers are ins. In the Chapter on Programming Constraint Propagation, we will show examples where actions and other types of triggers are used in delay clauses.


next up previous contents index
Next: Primitives on suspending variables Up: Delaying Previous: Delay clauses   Contents   Index
Neng-Fa Zhou
1999-11-24