Did you know ... | Search Documentation: |
![]() | block.pl -- Block: declare suspending predicates |
This module provides SICStus Prolog-compatible :- block BlockSpec,
...
declarations for delaying predicate calls if certain arguments are
unbound.
true
. A
blockspec evaluated to true
iff all arguments specified as `-' are
unbound.
Multiple BlockSpecs for a single predicate can appear in one or more
:- block
declarations. The predicate is suspended untill all mode
patterns that apply to it are satisfied.
The implementation is realised by creating a wrapper that checks the block conditions and either calls the original predicate immediately (if none of the block conditions were true) or uses attributed variables to delay re-evaluating the block condition until any of the arguments in question are bound.
-
, so that once any of them are bound, the
predicate is called again and the block conditions are re-evaluated.
If no block condition was true, the helper predicate fails.
Finally, an initialization clause is generated that sets up the actual wrapper. This wrapper first calls the helper predicate to check all block conditions and delay the call if necessary. If the helper predicate fails (i. e. no block condition was true), the wrapped predicate is called immediately.
The wrapper must be set up in an initialization clause and not as part of the term expansion, because wrap_predicate/4 wrappers are not retained in saved states, which would cause block declarations to break when loading a saved state.
-
, indicating that
the argument is part of the block condition.
This effectively generates an unrolled version of maplist(var,
ArgsToBlockOn), ConditionsTail
.