Too many attributes?

Yigal Chripun yigal100 at gmail.com
Fri Apr 25 10:38:06 PDT 2008


Janice Caron wrote:
> While I understand the reasons for "pure", etc. (- and don't
> misunderstand me, they are sound reasons!), there are implications for
> syntax which will come back and bite us if we're not careful. At the
> very least, I would suggest
> 
> (1) attributes for delegates
> (2) attribute tuples for templates
> 
> (e.g.
> 
>     AttributeTuple!(f) ReturnType!(f) foo(alias f)(ParameterTypeTuple!(f) n)
>     {
>         return f(n);
>     }
> 
> )

My example was a contrived one, but you provided good examples that
illustrates the syntactic issues that arise from all those additions to
D's syntax.

One note regarding your template example: I don't see how that
AttributeTuple!(f) helps.
this should be solved via introspection at runtime or via traits at
compile type. either way, it should be possible to get f's attributes in
 a tuple/array.
something like: f.attributesof which would return a tuple of attributes.
since I'm advocating for introduction of user defined attributes to D,
I'd suggest that the compiler should treat "const"/"pure" and such as
built-in attributes that are provided by the language, so that if you
define:
[myAttr1, myAttr2]
pure int func(invariant C c);

then func.attributesof would contain the tuple:
(pure, myAttr1, myAttr2).
just like a type tuple can contain both built-in types and user defined
ones.

--Yigal



More information about the Digitalmars-d mailing list