next up previous contents index
Next: 1.4 Ground, Numbervars, Subsumption, Up: 1. Library Utilities Previous: 1.2.1 Lowlevel Interface   Contents   Index


1.3 constraintLib: a library for CLP

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.

when(+Condition,Goal)
constraintLib
Delays the execution of Goal until Condition is satisfied, whereupon Goal will be executed. Condition can have the form

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)

unifiable(X, Y, -Unifier)
constraintLib
If X and Y can unify, succeeds unifying Unifier with a list of terms of the form Var = Value representing a most general unifier of X and Y. unifiable/3 can handle cyclic terms. Attributed variables are handles as normal variables. Associated hooks are not executed 1.4.


next up previous contents index
Next: 1.4 Ground, Numbervars, Subsumption, Up: 1. Library Utilities Previous: 1.2.1 Lowlevel Interface   Contents   Index
Terrance Swift 2007-10-06