Attributed variables (deprecated)
Author(s): Christian Holzbaur, Daniel Cabeza, Manuel Carro.
These predicates allow the manipulation of attributed variables. Attributes are special terms which are attached to a (free) variable, and are hidden from the normal Prolog computation. They can only be treated by using the predicates below.
Usage and interface
- Library usage:
:- use_module(engine(attributes)) - Exports:
- Predicates:
attach_attribute/2, get_attribute/2, update_attribute/2, detach_attribute/1. - Multifiles:
verify_attribute/2, combine_attributes/2.
- Predicates:
- Imports:
- Packages:
prelude, nonpure, assertions, nortchecks.
- Packages:
Documentation on exports
(Trust) Usage:attach_attribute(Var,Attr)
Attach attribute Attr to Var.
- The following properties should hold at call time:
(term_typing:var/1)Var is a free variable.
(term_typing:nonvar/1)Attr is currently a term which is not a free variable. - The following properties hold upon exit:
(term_typing:var/1)Var is a free variable.
(term_typing:nonvar/1)Attr is currently a term which is not a free variable.
(Trust) Usage:get_attribute(Var,Attr)
Unify Attr with the attribute of Var, or fail if Var has no attribute.
- The following properties should hold at call time:
(term_typing:var/1)Var is a free variable. - The following properties hold upon exit:
(term_typing:nonvar/1)Attr is currently a term which is not a free variable.
(Trust) Usage:update_attribute(Var,Attr)
Change the attribute of attributed variable Var to Attr.
- The following properties should hold at call time:
(term_typing:var/1)Var is a free variable.
(term_typing:nonvar/1)Attr is currently a term which is not a free variable. - The following properties hold upon exit:
(term_typing:var/1)Var is a free variable.
(term_typing:nonvar/1)Attr is currently a term which is not a free variable.
(Trust) Usage:detach_attribute(Var)
Take out the attribute from the attributed variable Var.
- The following properties should hold at call time:
(term_typing:var/1)Var is a free variable. - The following properties hold upon exit:
(term_typing:var/1)Var is a free variable.
Documentation on multifiles
(Trust) Usage:verify_attribute(Attr,Term)
A user defined predicate. This predicate is called when an attributed variable with attribute Attr is about to be unified with the non-variable term Term. The user should define this predicate (as multifile) in the modules implementing special unification.
- The following properties should hold at call time:
(term_typing:nonvar/1)Attr is currently a term which is not a free variable.
(term_typing:nonvar/1)Term is currently a term which is not a free variable. - The following properties hold upon exit:
(term_typing:nonvar/1)Attr is currently a term which is not a free variable.
(term_typing:nonvar/1)Term is currently a term which is not a free variable.
(Trust) Usage:combine_attributes(Var1,Var2)
A user defined predicate. This predicate is called when two attributed variables with attributes Var1 and Var2 are about to be unified. The user should define this predicate (as multifile) in the modules implementing special unification.
- The following properties should hold at call time:
(term_typing:var/1)Var1 is a free variable.
(term_typing:var/1)Var2 is a free variable. - The following properties hold upon exit:
(term_typing:var/1)Var1 is a free variable.
(term_typing:var/1)Var2 is a free variable.
Other information
Note that combine_attributes/2 and verify_attribute/2 are not called with the attributed variables involved, but with the corresponding attributes instead. The reasons are:- There are simple applications which only refer to the attributes.
- If the application wants to refer to the attributed variables themselves, they can be made part the attribute term. The implementation of freeze/2 utilizes this technique. Note that this does not lead to cyclic structures, as the connection between an attributed variable and its attribute is invisible to the pure parts of the Prolog implementation.
- If attributed variables were passed as arguments, the user code would have to refer to the attributes through an extra call to get_attribute/2.
- As the/one attribute is the first argument to each of the two predicates, indexing applies. Note that attributed variables themselves look like variables to the indexing mechanism.
However, future improvements may change or extend the interface to attributed variables in order to provide a richer and more expressive interface.
For customized output of attributed variables, please refer to the documentation of the predicate portray_attribute/2.
Known bugs and planned improvements
- Run-time checks have been reported not to work with this code. That means that either the assertions here, or the code that implements the run-time checks are erroneous.