digitalmars.D - lazy is broken, but we have delegates
- deadalnix (21/21) Apr 29 2012 OK, many people seems to want lazy to go.
- Peter Alexander (5/5) Apr 29 2012 So, in short, all expressions have an implicit conversion to
- deadalnix (4/9) Apr 29 2012 Yes, and delegate can be qualified with usual @safe nothrow pure or
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
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
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