Previous Up Next

17.9 Reading Terms with Attributed Variables

Although the parser can read and construct attributed variables, this feature is only useful in limited circumstances. This is because attributes often contain meta-information (e.g. relating to constraint solvers) that does not make sense for one variable in isolation. It is usually necessary to construct a variable attribute using the constructor predicate exported by the library that defines the corresponding attribute.

However, if an attribute is simple enough, a pair of writeq/2 and read/2 can be indeed be used to output a term with attributed variables in full, and reconstruct a corresponding term on input.

For clarity, only one occurrence of each variable in a term should have an attribute annotation, with each attribute occuring only once, as this is the canonical notation2

Note that in ECLiPSe source code, the attributed variable syntax should only be used in the head of matching clauses (see 17.5). In all other contexts, attributes will be ignored by the compiler.


2
If there are multiple annotations, they will be merged. Multiple occurrences of the same attribute are allowed as long as they are identical. The attributes are added one-by-one, as if with calls to add_attribute/3.

Previous Up Next