On 2009-08-01 23:36:57 -0400, "Robert Jacques" <[email protected]> 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
[email protected]
http://michelf.com/

Reply via email to