property syntax strawman

Sergey Gromov snake.scaly at gmail.com
Sun Aug 2 09:03:55 PDT 2009


Sun, 02 Aug 2009 00:43:43 -0700, Walter Bright wrote:

> Having optional parentheses does lead to unresolvable ambiguities. How 
> much of a problem that really is is debatable, but let's assume it 
> should be resolved. To resolve it, a property must be distinguishable 
> from a regular function.
> 
> One way is to simply add a "property" attribute keyword:
>
> The problem is that:
> 
> 1. there are a lot of keywords already
> 2. keywords are global things
> 
> The alternative is to have a unique syntax for properties. Ideally, the 
> syntax should be intuitive and mimic its use. After much fiddling, and 
> based on n.g. suggestions, Andrei and I penciled in:
> 
>    bool empty { ... }
>    void empty=(bool b) { ... }
> 
> [snip]
> 
>    bool empty{}

I don't like this part.  When I look at this syntax I think about weird
corner cases which will surface sooner or later.

You still didn't voice your opinion on annotations.  But if you do
consider them useful and think that they will get into the compiler
sooner or later, I propose this solution:

1.  Hack the front-end to allow '@' in *keywords*
2.  Add a "@property" keyword

This solution:

*  Cancels the "keywords are global" concern: @property can never
interfere with user-defined symbols
*  Does not add a keyword to the specs: @property being a keyword is
merely an implementation detail which goes away as soon as arbitrary
annotations are supported by the compiler
*  Implementation complexity is roughly the same as for simple keyword
addition which I believe is less complex than specialized syntaxes like
prop=()



More information about the Digitalmars-d mailing list