XSB supports constraint logic programming through its engine-level support of attributed variables (Section 1.2), and its support for constraint handling rules (CHR) (Chapter 11). The constraintLib library includes routines for delaying and examining bindings that are commonly used to implement CHR and other constraint libraries.
When processing constraints, it is often useful to delay a goal based on the instantiation level of a term or set of terms. For instance a 3 > X + Y should be delayed until both X and Y are instantiated. However the goal should be reinvoked as soon as possible after both are instantiated in order to prune search paths that may not be useful to pursue. The predicate when/2 provides a useful mechanism to delay goals based on instantiation patterns 1.2.
Example: The following session illustrates the use of when/2 to delay a goal.
|?- when(nonvar(X),writeln(test(1-2,nonvar))),writeln(test(1,nonvar)),X = f(_Y). test(1,nonvar) test(1 - 2,nonvar) X = f(_h245)