Previous Up Next

17.8 Printing Attributed Variables

The different output predicates treat attributed variables differently:

If there is only one handled attribute, the attributed variable is printed as

X{Attr}

where Attr is the value obtained from the handler. If there are several handled attributes, all attributes are qualified like in

X{a:A, b:B, c:C}.

A simple print handler can just return the attribute literally, like

print_attr(_{Attr}, PrintAttr) ?- PrintAttr=Attr.

An attributed variable X{m:a} with print handler print_attr/2 for the m-attribute, can thus be printed in different ways, e.g., 1

write(X{m:a})
or write_term(X{m:a}, [attributes(pretty)])
or printf("%mw", [X{m:a}])
    X{a}

write_term(X{m:a}, [attributes(none)])
or printf("%w", [X{m:a}])
    X

writeq(X{m:a})
    _g246{suspend : _g242, m : a}

write_term(X{m:a}, [attributes(full)])
or printf("%Mw", [X{m:a}])
    X{suspend : _g242, m : a}

Write macros for attributed variables are not allowed because one extension alone should not decide whether the other attributes will be printed or not.


1
The attribute suspend is always present and defined by system coroutining.

Previous Up Next