DIP4: Properties

KennyTM~ kennytm at gmail.com
Sat Jul 25 05:07:56 PDT 2009


Michel Fortin wrote:
> On 2009-07-25 06:10:09 -0400, Michiel Helvensteijn 
> <m.helvensteijn.remove at gmail.com> said:
> 
>> It's a little better. But there's still ambiguity:
>>
>> interface I {
>>     int foo;
>>     int opSet_foo(int);
>> }
>>
>> foo = 5; // which foo is used?
> 
> In the other thread, I suggested this, which could aleviate the problem:
> 
>     int foo.opGet();        // getter
>     void foo.opAssign(int); // setter
> 
> with some support from the compiler.
> 
> It could even be exteded to support more:
> 
>     int foo.opIndex(int); // foo[1];
>     void foo.opAddAssign(int); / foo += 1;
>     void foo.invert(); // special function attached to property
> 
> Basically, all you need to implement properties is not a dedicaced 
> "property" syntax, it's a syntax to implement some kind of local 
> namespace, and am "opGet" or "opValue" operator for representing the 
> local namespace. It could also be expressed like this:
> 
>     namespace foo {
>         int opGet(); // getter
>         void opAssign(int); // setter
>         ...
>         int opIndex(int); // foo[1];
>         void opAddAssign(int); / foo += 1;
>         void invert(); // special function attached to property
>     }
> 
> In both cases, the result would be the same:
> 
>     foo = 1; // same as foo.opAssign(1);
>     return foo; // same as return foo.opGet();
> 

If property is going to be extended like this, why not just make a 
nested struct. Works even now.



More information about the Digitalmars-d mailing list