lazy variables cannot be lvalues - why?
Adam Cigánek
adam.ciganek at gmail.com
Mon Nov 1 08:57:09 PDT 2010
Hello,
why is the following code illegal?
import std.stdio;
void delegate() fun;
void capture(lazy void f) {
fun = &f;
}
void main() {
capture(writeln("hello"));
fun();
}
It says "Error: lazy variables cannot be lvalues", pointing to the
"fun = &f" line.
It can be worked around by rewriting it like this:
void capture(lazy void f) {
fun = delegate void() { f(); };
}
So it's not big deal, just a minor inconvenience. But still, why is it
illegal? According to the docs
(http://www.digitalmars.com/d/2.0/lazy-evaluation.html), lazy
expressions are implicitly converted to delegates, so it seems to me
that it should work.
adam.
More information about the Digitalmars-d-learn
mailing list