|
Archives
D Programming
DD.gnu digitalmars.D digitalmars.D.bugs digitalmars.D.dtl digitalmars.D.dwt digitalmars.D.announce digitalmars.D.learn digitalmars.D.debugger C/C++ Programming
c++c++.announce c++.atl c++.beta c++.chat c++.command-line c++.dos c++.dos.16-bits c++.dos.32-bits c++.idde c++.mfc c++.rtl c++.stl c++.stl.hp c++.stl.port c++.stl.sgi c++.stlsoft c++.windows c++.windows.16-bits c++.windows.32-bits c++.wxwindows digitalmars.empire digitalmars.DMDScript |
digitalmars.D - repost: semantics of the keyword lazy
I have posted the following in the learn-group without any answers:
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 11 2006
On Thu, 12 Oct 2006 03:08:07 +0000 (UTC), Karen Lanrap wrote:I have posted the following in the learn-group without any answers: 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 :-( Oct 11 2006
I was wondering what would happen if you call the lazy "delegate" multiple times. will the result be cached or will the delegate/function be called multiple times? Oct 11 2006
On Wed, 11 Oct 2006 22:56:59 -0600, Hasan Aljudy wrote:I was wondering what would happen if you call the lazy "delegate" multiple times. will the result be cached or will the delegate/function be called multiple times? Oct 12 2006
Derek Parnell wrote:Whenever the called function decides to do it, if at all. Oct 12 2006
Karen Lanrap wrote:I have posted the following in the learn-group without any answers: 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 :-( Oct 12 2006
Ivan Senji wrote:The thing is: argument and parameter are not one and the same and that makes the definition not circular. Oct 13 2006
|