Daniel Keep escribió:

Walter Bright wrote:
Daniel Keep wrote:
That's true, but you haven't addressed the other side of it: property
setters.
Right. Consider the case where there's a pure function with no
arguments, and an overload with the same name and one argument, and no
other overloads. Wouldn't it be reasonable to take that as a property
setter?

With D, you would need to explicitly state which methods are properties
manually somehow; dunno how you would, though.  Especially when you
consider subclassing and mixins.
See my rule above - I think it'll work.

Actually, I've now come up with a counter-example for the idea of using
pure at all:

class Lazy(T)
{
    private
    {
        T v;
        T delegate() dg;
    }
    this(T delegate() dg) { this.dg = dg; }
    T value()
    {
        if( dg !is null )
        {
            v = dg();
            dg = null;
        }
        return v;
    }
}

You can't make value pure, but it is supposed to be a property.  One of
the examples Nick gives in DIP4 is a property that accesses an SQL
database; there's no way to make that pure!

Exactly! That's why I said "kind of pure" (well, maybe I didn't say that :-P), but the idea is that properties don't modify anything visible from outside of the symbol they are contained in. But it's hard to define what that means...

Reply via email to