User Defined Attributes
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Thu Nov 8 01:14:26 PST 2012
On 11/8/12 12:20 AM, Walter Bright wrote:
> One last thing. Sure, string attributes can (and surely would be) used
> for different purposes in different libraries. The presumption is that
> this would cause a conflict. But would it? There are two aspects to a
> UDA - the attribute itself, and the symbol it is attached to. In order
> to get the UDA for a symbol, one has to look up the symbol. There isn't
> a global repository of symbols in D. You'd have to say "I want to look
> in module X for symbols." Why would you look in module X for an
> attribute that you have no reason to believe applies to symbols from X?
> How would an attribute for module X's symbols leak out of X on their own?
Actually there's a stark difference between string attributes and symbol
attributes (assuming I understand the point): attribute lookup and
potential ambiguity are solved using regular symbol lookup and potential
ambiguity - by using name resolution. In contrast, string attributes
have no other resolution mechanism than string comparison.
So now say two modules moda and modb define an attribute "untainted"
with distinct semantics. If "untainted" is a string, there's no way out
of this - the modules simply cannot work together. In contrast, if
untainted is a regular symbol, it will cause ambiguity errors that are
solvable by using qualified lookup a la moda.untainted and modb.untainted.
Andrei
More information about the Digitalmars-d-announce
mailing list