Fixing const arrays

Regan Heath regan at netmail.co.nz
Wed Dec 14 05:27:57 PST 2011


On Wed, 14 Dec 2011 02:36:43 -0000, Michel Fortin  
<michel.fortin at michelf.com> wrote:

> On 2011-12-13 23:08:43 +0000, Andrei Alexandrescu  
> <SeeWebsiteForEmail at erdani.org> said:
>
>> We could have inferred property intention from the code pattern,  
>> without requiring any keyword. That solution (which was discussed and  
>> rejected in this newsgroup) was miles ahead from the drivel of  
>> @property we have now.
>
> By "code patterns", you mean something like this?
>
> 	struct Foo
> 	{
> 		int getBar();
> 		void setBar(int);
> 	}
>
> 	void main()
> 	{
> 		Foo foo;
> 		int a = foo.bar;  // calls getBar()
> 		foo.bar = a;      // calls setBar(a)
> 	}

Why not something similar to C# syntax...

struct Foo
{
   int bar		// <- does DMD do lookahead?  detect { instead of ; here and  
trigger "property" parsing
   {
     get
     {
       return value;  // <- 'value' meaning the value of the 'bar' member
     }
     set
     {
       this = value; // <- 'this' meaning the 'bar' member, 'value' meaning  
the RHS of the "£instance.bar = <value>" statement
     }
   }
}

Regan


More information about the Digitalmars-d mailing list