Passing lazy parmeters to functions that take lazy parameters

Jari-Matti Mäkelä jmjmak at utu.fi.invalid
Mon Sep 4 16:01:12 PDT 2006


Joe Gottman wrote:
> "Walter Bright" <newshound at digitalmars.com> wrote in message 
> news:edi8s6$olu$1 at digitaldaemon.com...
>> Joe Gottman wrote:
>>> Suppose I have a function f that has a lazy parameter x, and I pass it 
>>> into another function g that has a lazy parameter.  Will x be evaluated 
>>> when it is passed to g?
>> No, it isn't evaluated. The evaluation of it is wrapped up into another 
>> delegate and passed to g.
> 
> OK.  So what's the best way to force evaluation?  Would just mentioning it 
> in a line by itself work?

Because g also uses lazy evaluation you have to evaluate x in f before
giving it forward as an argument to g. Still, the evaluated value gets
wrapped up into a delegate before it's finally usable in g as a simple
value.

The best way might be not to use lazy evaluation if it's not necessary.



More information about the Digitalmars-d mailing list