Module verify

This module provides a type 2 interface to attributed variables. The trailed state of the at-tributed variable is modelled as key value pairs and can be accessed and modified by the predicates put_atts/3, get_atts/3 and del_atts/2. When an attributed variable with type 2 states gets instantiated the attributed variable verify hooks are called immediately.

Example:
?- [user].
foo:verify_attributes(L, _) :-
write('L='), write(L), nl.
^D
Yes
?- put_atts(X, foo, [X,Y]), put_atts(Y, foo, [X,Y]), [X,Y]=[1,2].
L=[_A,_B]
L=[1,_B]
?- put_atts(X, foo, [X,Y]), put_atts(Y, foo, [X,Y]), X=Y.
L=[_A,_B]

The verify hook verify_attributes/2 has to be declared inside the module of the key. The hook is called before the variable has been instantiated and receive the attribute value in its first argument. The hook is allowed to fail or succeed, but it is called only once. If the hook fails the surrounding unification will also fail.

The goals hook portray_attributes/3 has to be optionally declared inside the module of the key. When needed the hook is called only once. If the hook is missing or if it fails a single goal for a put_atts/3 call is generated. The goals are used in the top-level display of answers and they can be retrieved by the call_residue/2 predicate from the module residue.

The following verify predicates are provided.

put_atts(V, K, W):
The predicate assigns the value W to the key K of the variable V. The assignment is automatically undone upon backtracking.
get_atts(V, K, W):
The predicate succeeds for the value W of the key K of the variable V.
del_atts(V, K):
The predicate de-assigns the key K from the variable V. The de-assignment is automatically undone upon backtracking.
K:verify_attributes(W, T) (hook):
This predicate has to be implemented as a hook for a key K. It will be called with the value W and the term T before the unification.
K:portray_attributes(V, I, O) (hook):
This predicate has to be optionally implemented as a hook for a key K. It will be called when the goals by the variable V are needed. It should return a list of goals in I. The list uses the end O.

Comments