new DIP5: Properties 2

Michel Fortin michel.fortin at michelf.com
Sun Aug 2 03:58:04 PDT 2009


On 2009-08-01 23:36:57 -0400, "Robert Jacques" <sandford at jhu.edu> said:

> Hmm... I just had a crazy thought, regarding Andrei's enum bool empty = 
>  false; example. What if in addition to functions as fields (aka  
> properties) D allowed fields as functions? i.e.
> c.foo(5); => c.foo = 5
> when method foo doesn't exist.

Sure, you could make fields behave as function. For instance:

	int foo;
	
	foo(5); // same as foo = 5;
	int bar(foo()); // same as bar = foo;

But then you'll have some problems with delegates and types that define opCall:

	void delegate(int) foo;

	foo(5); // foo = 5 or a call to the delegate?
	foo()(5); // should the delegate be called this way?

and this:

	void delegate() foo;

	void delegate() bar(foo()); // same as bar = foo, or a call to the delegate?

You'll need to always write foo()() to call the delegate, which I admit 
is more coherent that what we have now with properties, but also 
somewhat counterintuitive.

-- 
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/




More information about the Digitalmars-d mailing list