next up previous contents index
Next: Implementing freeze by using Up: Delaying Previous: Delaying   Contents   Index

Delay clauses

A delay clause takes the following form:

delay Head :- Condition : [{Triggers}] Action.
where Condition is a sequence of in-line tests, Triggers, which is optional, is a sequence of trigger declarations, and Action is a sequence of arbitrary calls. There is a special in-line test, called no_vars_gt(N,M), that can appear in the condition part of a delay clause. The condition no_vars_gt(N,M) is true for a call when the last N arguments of the call contain more than M variables.

For any call to the predicate of Head, if it matches Head ( i.e., the call is an instance of Head) and Condition is satisfied, then the call delays and Action is executed. Since one-directional matching rather than full-unification is used to match the call against Head and Condition is composed of only in-line tests, the call will be kept unchanged before Action is executed. If the call does not match Head or Condition fails, then the next clause will be tried. If Action fails, then the original predicate call will fail. Notice that delay clauses are different from guarded clauses in concurrent languages and the ':' does not mean commitment. After a delay clause is chosen, the predicate can be reentered and the remaining clauses can be retried later.

The sequence of trigger declarations Triggers declares when the clause should be re-executed. The trigger declaration ins(X) means the time when the variable X is instantiated; min(X) ( max(X)) means the time when the low (upper) bound of X is updated; and dom(X) means the time when any intermediate element is excluded from X's domain. The triggers min(X), max(X), and dom(X) apply only to domain variables. When no trigger declaration is given, the compiler automatically generates a trigger ins(X) for each variable occurring in Condition. After a call is delayed, variables in triggers (which must also appear in the call) will become suspending variables.

A delay clause is executed in an event-driven manner. At the entry and exit points of every predicate, the system checks to see whether or not there is a trigger that has been turned on. If so, then the current procedure is interrupted and control is moved to the lists of constraints associated with the trigger. After the constraints finish their execution, the interrupted procedure will resume its execution.

A predicate that contains at least one delay clause is called a delay predicate. All non-delay clauses in a delay predicate must be in canonical-form, and delay predicates must be compiled and loaded into the system for execution (this means delay predicates cannot be interpreted directly).


next up previous contents index
Next: Implementing freeze by using Up: Delaying Previous: Delaying   Contents   Index
Neng-Fa Zhou
1999-11-24