lazy evaluation

Julio César Carrascal Urquijo jcesar at phreaker.net
Fri Jun 1 16:35:17 PDT 2007


Pierre Habouzit wrote:
>   Whereas I would have expected 0 and ... 0. I know the code I show is
> well, nasty as the lazy expression has a side effect, but it was just a
> way for me to test if lazy expressions were memoized (what I really
> expected) or not. It appears they are not, and well, that's not good.

If you want to use the result of the argument more than once you should 
store that in a local variable:

void bar(lazy int i) {
     int j = i();
     baz(j);
     writefln("bar %d", j);
}


>   * also why it's not a generic type attribute either and only used as a
>     function parameter. Not knowing the implementation gory details, I
>     don't know if it makes sense at all anyway.

Walter gave us indications that the behavior would change as part of the 
"const clean-up" currently undergoing. This seams like a good time to 
share your thoughts and improvements on the behavior of lazy.



More information about the Digitalmars-d mailing list