Lazy evaluation of function pointers.

Ryan Frame via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Apr 10 11:08:58 PDT 2016


Greetings.

The following code works:

void main() {
     passfunc(&func);
}

void passfunc(void function(string) f) {
     f("Hello");
}

void func(string str) {
     import std.stdio : writeln;
     writeln(str);
}

Now if I change passfunc's signature to "void passfunc(lazy void 
function(string) f)" I would get the compiler error "Delegate f 
() is not callable using argument types (string)". I can lazily 
pass a void function() -- it seems that there is only a problem 
when the function contains parameters.

The only difference should be when the pointer is evaluated, so 
why does lazy evaluation matter here?

Thank you for your time
--Ryan


More information about the Digitalmars-d-learn mailing list