DIP23 draft: Fixing properties redux

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Mon Feb 4 14:16:22 PST 2013


On 2/4/13 9:25 AM, Timon Gehr wrote:
> On 02/04/2013 03:05 PM, Andrei Alexandrescu wrote:
>> I think the sensible disambiguation is to
>> have &fun take the address of fun and the other two take the address of
>> fun's result.
>>
>
> No! &fun and &(fun) are the same thing. Functions that get their address
> taken are not implicitly invoked. (Again, Scala agrees.)
>
> The rules are straightforward:
>
> A non- at property function name 'foo' denotes a function invocation
> without arguments iff it does not occur in one of the following contexts:
>
> 1. foo(...) // explicitly called
> 2. &foo // address taken
> 3. ...!(...,foo,...) // template argument (well, that's what DMD
> currently does)
> 4. alias ... = foo; // aliased

The problem with (3) is that it creates a rule that gives different 
meaning of expressions inside &(...) and outside it. Consider:

&foo -> fine, takes the address of foo
&(foo) -> parens don't matter, sweet, still takes the address of foo
&( condition ? foo : bar ) -> hum, I guess takes the address of foo or bar
&( { auto a = foo; ... return c ? foo : bar; }() ) -> what???

So this is essentially a rule that makes the same give expression have a 
meaning inside &( ... ) and a different meaning outside.

In &expr.name and &(expr.name), that's it - expr may be arbitrarily 
complicated, but the construct must always end with a method name. In 
&name and &(name), it's even simpler - it's just punctuation.


Andrei


More information about the Digitalmars-d mailing list