On Saturday 25 September 2010 22:59:51 Don wrote: > Jonathan M Davis wrote: > > On Saturday 25 September 2010 03:23:12 Torarin wrote: > >> 2010/9/24 Jonathan M Davis <jmdavisp...@gmx.com>: > >>> However, we're not going to double the number of keywords that we have, > >>> and the @ syntax has allowed us to remove some keywords and will allow > >>> us to add more stuff later without having to add keywords. > >> > >> Why are attributes not considered keywords? Because the compiler > >> doesn't care about them? > > > > Because they don't need to be any more than variable names do. @ > > indicates that what follows is an attribute, so the next symbol is > > parsed as an attribute. If it were a keyword, then it wouldn't compile. > > keywords are always treated as keywords no matter the context. They show > > up explicitly in the grammar. Attributes do not show up explicitly in > > the grammar any more than variables do. The grammar indicates when a > > symbol is a variable, and it's parsed as variables. The grammar also > > indicates when a symbol is an attribute, and it's parsed as an > > attribute. > > > > Basically, what it comes down to is that keywords are symbols in the > > grammar - just like ! or ~ or <. Variable names and attributes are not. > > > > Attributes allow us to add more modifiers to stuff (particularly > > functions) without having to add new keywords. And someday, we may even > > be able to define attributes in our own code (right now, they're all > > known by the compiler) - and that's something that you obviously can't > > do with keywords. > > > > - Jonathan M Davis > > You can already do that by prefixing with __.
Do you mean that you can use user-defined attributes as long as they're prefixed with _ or that you can use keywords if they're prefixed with _? Prefixing a keyword with _ makes it so that it's a different token, so it's not going to match any keywords. Now, if you mean that you could use your own attributes as long as they start with an underscore (.e.g. @_myproperty), then that could be useful, but I don't know how you'd be able to make use of it, since you'd need a way to get at through __traits or std.traits, and functionAttributes() (which is the only function that I see for looking at attributes) isn't string-based but rather flag-based, which means that it won't work with anything but a predefined set of attributes. - Jonathan M Davis