new DIP5: Properties 2
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Tue Jul 28 11:23:55 PDT 2009
Jimbob wrote:
> "Kagamin" <spam at here.lot> wrote in message
> news:h4jq11$1jvq$1 at digitalmars.com...
>> http://prowiki.org/wiki4d/wiki.cgi?LanguageDevel/DIPs/DIP5
>>
>> As namespaces were proposed, a variant of them is in DIP5 now.
>
> Why not just..
>
> class Foo
> {
> private:
> int mx;
> public:
> int x.opGet() { return mx; }
> void x.opSet(int i) { mx = i; }
> void x.opInc() { mx++; }
> }
>
> or instead...
>
> class Foo
> {
> private:
> int mx;
> public:
> int x:opGet() { return mx; }
> void x:opSet(int i) { mx = i; }
> void x:opInc() { mx++; }
> }
>
> So that
>
> foo.x++;
>
> Would be compiled as
>
> foo.x.opInc();
>
> In the same way
>
> foo++;
>
> Would is compiled as
>
> foo.opInc();
Nice. Is x.opGet overridable?
This is a trick question hinting at the fact that you'd need to define
that. I presume it's reasonable to say it is, unless people say
final int x.opGet() { ... }
or something. My point is that when you define new syntax you must add a
host of ancillary definitions that reveal how it interacts with the
existing language. This problem is obviated by the lowering approach.
Andrei
More information about the Digitalmars-d
mailing list