DIP23 draft: Fixing properties redux

kenji hara k.hara.pg at gmail.com
Sun Feb 3 21:53:06 PST 2013


2013/2/4 Andrei Alexandrescu <SeeWebsiteForEmail at erdani.org>

> On 2/3/13 11:00 PM, David Nadlinger wrote:
>
>>
>>  Now, grouping the expression »&a.b« according to the precedence rules
>> yields »&(a.b)« – but in your proposal, they mean completely different
>> things.
>>
>
> I agree they mean different things. I'm unclear that's a problem. All your
> examples stop here, there's no propagation of the issue. To take the
> address of a property, one writes &obj.prop. To take the address of a
> property's result, one writes &(obj.prop). And that's that. It all works
> with typeof.


If the expression is generated from string mixin, might have a problem.

// This is much simple case. Real example might be more complicated.
template AddressOf(string exp)
{
    enum AddressOf = "&" ~ exp;
}
struct S {
    @property int prop() { return 1; }
}
void main() {
    S s;
    assert(s.prop == 1);
    int* p = mixin(AddressOf!("s.prop"));  // &s.prop returns delegate
}

I think that parenthesis-dependent syntax is not good.

Kenji Hara
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20130204/99fd3f8a/attachment.html>


More information about the Digitalmars-d mailing list