www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - lazy is broken, but we have delegates

reply deadalnix <deadalnix gmail.com> writes:
OK, many people seems to want lazy to go.

it is understandable : the feature is broken. lazy imply computation 
inside the function, but it is impossible to ensure anything about that 
computation (is it pure ? is it nothrow ? is it  safe, etc . . .).

In fact, to be usefull, lazy need to be able to be qualified with any 
qualifier that a delegate can have. So, let's remove lazy completely.

Now we have to ensure that any expression can create a delegate that 
return a type covariant with given expression's type and with no 
argument automagicaly. And DONE !

The exact same thing can no be achieved, but without the lazy mess. With 
some code :

int delegate() foo = 3;

3 is an expression. foo is now a delegate that always return 3.

Foobar delegate() foo = new Foobar();

foo is a delegate creating a new Foobar object each time it is called.

log(string delegate() tolog) {
     // code . . .
}

log("foo" ~ myObject.toString());

log is called and tolog is a delegate equivalent to delegate string() { 
return "foo" ~ myObject.toString(); }
Apr 29 2012
parent reply "Peter Alexander" <peter.alexander.au gmail.com> writes:
So, in short, all expressions have an implicit conversion to 
'typeof(Expression) delegate()'.

Seems reasonable at first glance, although I get the feeling it 
will have nasty edge cases. Implicit conversions generally do 
seem to cause trouble.
Apr 29 2012
parent deadalnix <deadalnix gmail.com> writes:
Le 30/04/2012 00:03, Peter Alexander a écrit :
 So, in short, all expressions have an implicit conversion to
 'typeof(Expression) delegate()'.

 Seems reasonable at first glance, although I get the feeling it will
 have nasty edge cases. Implicit conversions generally do seem to cause
 trouble.
Yes, and delegate can be qualified with usual safe nothrow pure or whatever if it valid depending on the Expression. The return type can be typeof(Expression) but also any covariant type.
Apr 29 2012