Block declarations

Author(s): Rémy Haemmerlé, Jose F. Morales (documentation improvements).

Version: 0.1 (2008/25/5) This package provides compatibility with SICStus' block declarations.

Convention: The recommended style is to write the block declarations in front of the source code of the predicate they refer to. Indeed, they are part of the source code of the predicate and must precede the first clause. Moreover it is suggested to use ? for specifying non conditioned arguments.

Example: The following definition calls to merge/3 having uninstantiated arguments in the first and third position or in the second and third position will suspend.

:- block merge(-,?,-), merge(?,-,-).

merge([], Y, Y).
merge(X, [], X).
merge([H|X], [E|Y], [H|Z]) :- H @< E,  merge(X, [E|Y], Z).
merge([H|X], [E|Y], [E|Z]) :- H @>= E, merge([H|X], Y, Z).

Simulating block with when/2 predicate: In the predicate above, execution of merge(X,Y,Z) is suspended while (var(X),var(Z);var(Y),var(Z)) holds. A similar effect can be obtained with when/2 using the negated condition ((nonvar(X);nonvar(Z)),(nonvar(Y);nonvar(Z))).

:- use_module(library(when)).

merge(X,Y,Z) :-
	when(((nonvar(X);nonvar(Z)),
              (nonvar(Y);nonvar(Z))), merge_(X,Y,Z)).

merge_([], Y, Y).
merge_(X, [], X).
merge_([H|X], [E|Y], [H|Z]) :- H @< E,  merge(X, [E|Y], Z).
merge_([H|X], [E|Y], [E|Z]) :- H @>= E, merge([H|X], Y, Z).

Usage and interface

Documentation on new declarations

DECLARATIONblock/1

Usage::- block(BlockSpecs).

BlockSpecs specifies a disjunction of conditions. Each condition is of the form predname(C1, ..., CN) where each CI is either a - if the call must suspend until the corresponding argument is bound, or anything else otherwise.