Attribute variables permit to extend unification. The following is about arcane details of the interface. Let's cut right to the chase!
In sicstus-prolog
library(atts) provides predicates for using attributed variables.
I think I get what the SICStus Prolog User's Manual page for library(atts) says, except for one detail about verify_attributes(-Var, +Value, -Goals)
:
[...] verify_attributes/3 is called before Var has actually been bound to Value. If it fails, the unification is deemed to have failed. It may succeed nondeterminately, in which case the unification might backtrack to give another answer. It is expected to return, in Goals, a list of goals to be called after Var has been bound to Value. Finally, after calling Goals, any goals blocked on Var are called.
The above sentence (highlighted by me) confused me—and a lot, too:)
I have always thought that unification is a procedure that could either:
succeed with the most general unifier (modulo variable renaming)
or fail.
But succeed nondeterminately?!
When is that "feature" ever of use to implementors of constraint solvers?
I can't think of a single use case... help please!
EDIT
Actually, I regard non-determinacy in (my) solver code a bug—not a feature. For any non-determinacy can easily be emulated by returning some disjunction in Goals
.
freeze( X, ( X = 1 ; X = 2 ) )
– falsefreeze(X, ( Y = 1 ; Y = 2 ) )
– falseGoals
argument for unfrozen goals... – repeatY
may be unified when unfreezingX
. But it can easily be done withGoals = [(Y = 1 ; Y = 2)]
. – repeatclpq
orclpr
orclpb
need it, and I don't get it with myclpfd
-glasses on:) – repeat