lazy is broken, but we have delegates
deadalnix
deadalnix at gmail.com
Sun Apr 29 14:59:57 PDT 2012
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(); }
More information about the Digitalmars-d
mailing list