Make dur a property?

Adam D. Ruppe destructionator at gmail.com
Wed Jan 23 10:08:09 PST 2013


On Wednesday, 23 January 2013 at 17:47:44 UTC, H. S. Teoh wrote:
> I'm starting to think that perhaps @property should be disposed 
> of completely.

There is a problem @property can potentially solve: a property 
returning a callable.

alias void delegate() Callable;

struct test {
    @property Callable foo() { ... }
}

test t;
Callable c = t.foo; // should work
t.foo(); // should call the returned function
t.foo()(); // this should NOT work


Currently, t.foo()() DOES work and t.foo() gives the callable, 
without actually calling it (i.e. does not work as it should).

-property and the current @property implementation do not even 
try to address this.




My preferred solution is:

1) all functions without @property work exactly the same way they 
do now (optional parenthesis, callable as setters with =)

2) all functions with @property are ALWAYS rewritten so that a 
reference to them instead references the return value and/or the 
setter function.

So the result would be similar to #define t.foo (t.foo()). The 
type system then takes care of the parenthesis - no special code 
is required for syntax.


More information about the Digitalmars-d mailing list