www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - semantics of keyword lazy

From the documentation:

Lazy arguments are evaluated not when the function is called, but 
when the parameter is evaluated within the function.


First to note, that this is a circular definition without any fixed 
point to start from:
a lazy argument is evaluated, when it is evaluated :-(


Maybe Walter meant something like this:
With the exception of lazy parameters all actual parameters are 
passed evaluated to the function they belong to.


But this does not help for lazy parameters: when the hell are they 
evaluated?

"Within the function" Walters says. But what does this mean if the 
calling function is recursive or combined with parameters that are 
not lazy evaluated? Example:

int ack( lazy bool b, int x, lazy int y){
    if( x == 0 )
        if( b) return y+1;
    else
        if( y == 0)
            return ack( b, x-1, 1);
        else
            return ack( b, x-1, ack( b, x, y-1));
}

If Walter wanted to express, that lazy parameters must be evaluated 
in the calling function, then I understand, but I doubt, that this 
concept is that useful.

If on the other hand lazy parameters can be passed down through 
function hierarchies one should be able to protect them from 
accidental evaluation until they reach the target point of their 
evaluation, i.e. something like

      if( unlazy b) return y+1;

should be possible and
 
      ack( x, b, y-1)

should show up as an error because the target is not notified as

      ack( x, unlazy b, y-1)
Oct 04 2006