Previous Up Next

17.5  Declarative Suspension: Delay Clauses

For delaying calls to user-defined Prolog predicates, ECLiPSe provides several alternatives, the first being delay clauses. Delay clauses are a declarative means (they are in fact meta-clauses) to specify the conditions under which the predicate should delay. The semantics of delay clauses is thus cleaner than many alternative approaches to delay primitives.

A delay clause is very similar to a normal Prolog clause. It has the form
delay <Head> if <Body>.
A predicate may have one or more delay clauses. They have to be textually before and consecutive with the normal clauses of the predicate they belong to. The simplest example for a delay clause is one that checks if a variable is instantiated:
delay report_binding(X) if var(X).
report_binding(X) :-
        printf("Variable has been bound to %w\n", [X]).
The operational semantics of the delay clauses is as follows: when a procedure with delay clauses is called, then the delay clauses are executed before executing the procedure itself. If one of the delay clauses succeeds, the call is suspended, otherwise they are all tried in sequence and, if all delay clauses fail, the procedure is executed as usual.

The mechanism of executing a delay clause is similar to normal Prolog clauses with two exceptions: The reason for using pattern matching instead of unification is to avoid a possible mixing of meta-level control with the object level, similarly to [3].

The form of the head of a delay clause is not restricted. For the body, the following conditions hold:

More Examples

CAUTION: It may happen that the symbol :- is erroneously used instead of if in the delay clause. To indicate this error, the compiler complains about redefinition of the built-in predicate delay/1.

Previous Up Next