[Issue 2939] lazy evaluation not invoked for lambda function
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue May 5 10:35:51 PDT 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2939
------- Comment #5 from shro8822 at vandals.uidaho.edu 2009-05-05 12:36 -------
I think this is working correctly:
take this example:
import std.stdio;
void fn(lazy int i)
{
writef("%d\n", k);
auto j = i();
writef("%d\n", k);
auto h = i();
writef("%d\n", k);
}
int k = 0;
void main()
{
writef("%d\n", k);
fn(k++);
writef("%d\n", k);
}
output:
0
0
1
2
2
What is happening in the original cases is that the 'dg();' is evaluating *to
the* lambda rather than *evaluating* the lambda. And this is correct as the
expression that f was called with is the lambda. (If there is a problem here is
it the old one of the skipping the perens on void functions thing)
To look at it another way, dg is (almost):
delegate void(){ return delegate void(){ ok = true; } }
(it's got to play around a bit with context pointers and whatnot but that's
side issue)
--
More information about the Digitalmars-d-bugs
mailing list