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:
foo:verify_attributes(L, _) :-
write('L='), write(L), nl.
?- put_atts(X, foo, [X,Y]), put_atts(Y, foo, [X,Y]), [X,Y]=[1,2].
?- put_atts(X, foo, [X,Y]), put_atts(Y, foo, [X,Y]), X=Y.
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.