Attributed variables

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

Documentation on exports

PREDICATE

Usage: attach_attribute(Var,Attr)

  • Description: 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.

PREDICATE

Usage: get_attribute(Var,Attr)

  • Description: 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.

PREDICATE

Usage: update_attribute(Var,Attr)

  • Description: 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.

PREDICATE

Usage: detach_attribute(Var)

  • Description: 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

PREDICATE

The predicate is multifile.

Usage: verify_attribute(Attr,Term)

  • Description: 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.

PREDICATE

The predicate is multifile.

Usage: combine_attributes(Var1,Var2)

  • Description: 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.