digitalmars.D - Passing lazy parmeters to functions that take lazy parameters
- Joe Gottman (14/14) Sep 04 2006 Suppose I have a function f that has a lazy parameter x, and I pass it i...
 - Walter Bright (3/6) Sep 04 2006 No, it isn't evaluated. The evaluation of it is wrapped up into another
 - Joe Gottman (5/11) Sep 04 2006 OK. So what's the best way to force evaluation? Would just mentioning ...
 - =?ISO-8859-1?Q?Jari-Matti_M=E4kel=E4?= (6/17) Sep 04 2006 Because g also uses lazy evaluation you have to evaluate x in f before
 - Walter Bright (2/4) Sep 04 2006 Yes.
 - Unknown W. Brackets (7/14) Sep 04 2006 Is it necessary to wrap it in another delegate?
 
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?  For instance:
void g(lazy int x) {/* Do nothing */}
void f (lazy int x) {
    g(x);  //Is x evaluated here?
}
void main()
{
   int x = 0;
   f(++x);
    printf("%d\n", x); //Do we print 0 or 1?
}
Joe Gottman 
 Sep 04 2006
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.
 Sep 04 2006
"Walter Bright" <newshound digitalmars.com> wrote in message news:edi8s6$olu$1 digitaldaemon.com...Joe Gottman wrote:OK. So what's the best way to force evaluation? Would just mentioning it in a line by itself work? Joe GottmanSuppose 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.
 Sep 04 2006
Joe Gottman wrote:"Walter Bright" <newshound digitalmars.com> wrote in message news:edi8s6$olu$1 digitaldaemon.com...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.Joe Gottman wrote:OK. So what's the best way to force evaluation? Would just mentioning it in a line by itself work?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.
 Sep 04 2006
Joe Gottman wrote:OK. So what's the best way to force evaluation? Would just mentioning it in a line by itself work?Yes.
 Sep 04 2006
Is it necessary to wrap it in another delegate? Assuming it already has a delegate which returns int, it seems a possible optimization to simply pass this existing delegate on, without packaging it further... Is that not the case, or simply a field for future optimization? Thanks, -[Unknown]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.
 Sep 04 2006








 
 
 
 =?ISO-8859-1?Q?Jari-Matti_M=E4kel=E4?= <jmjmak utu.fi.invalid> 