[ Term Manipulation | Reference Manual | Alphabetic Index ]

add_attribute(?Var, ?Attribute, +Module)

Add dynamically an attribute to a variable.
Var
Any term.
Attribute
Any term.
Module
Integer or atom.

Description

The main use of this predicate is for dynamic attributed variables creation. Since the number of declared extensions can vary with time, attributes explicitly occurring in the source of extensions might be created with less slots than currently necessary. To make sure that a newly created attributed variable will have as many slots as necessary, this predicate should be preferred to the equivalent

    Var = _{Attribute}
If Var is a free variable, it will be bound to a new attributed variable whose attribute corresponding to Module will be Attribute. If Var is already an attributed variable and the corresponding attribute is a free variable, it will be bound to Attribute. Otherwise, if the attribute is not a free variable or if Var is instantiated, it will be unified with a new attributed variable whose corresponding attribute is Attribute and all other attributes are free variables.

If Module is an atom, the attribute corresponding to a previous meta_attribute declaration will be used. If Module is an integer, it is directly used as the index slot (this is mainly used by the compiler to resolve attribute references at compile time).

Modes and Determinism

Fail Conditions

Fails if Var is not a free variable and its unification with the new attributed variable fails

Exceptions

(270) undefined variable attribute
There is no attribute declared in Module.

Examples

[eclipse 6]: meta_attribute(extra, []).

yes.
[eclipse 3]: add_attribute(X, a, extra), printf("%QPMw", X).
X{suspend : _g270 , extra : a}
X = X
yes




See Also

meta_attribute / 2, add_attribute / 2