in reply to Re^36: Why is the execution order of subexpressions undefined? (magic ruts)
in thread Why is the execution order of subexpressions undefined?

Hmm. I though lazy evaluation meant that the value wasn't calculated until needed.

If f() is a lazy evaluating function and I call it, it will give a result. The only way it wouldn't get called in the statement

result = f(a) * g(b) + h(c);

is if the compiler took it upon itself to override my explicit request to call it. If perl ever starts doing that, I'm gonna use VB!


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco.
Rule 1 has a caveat! -- Who broke the cabal?
  • Comment on Re^37: Why is the execution order of subexpressions undefined? (magic ruts)
  • Download Code

Replies are listed 'Best First'.
Re^38: Why is the execution order of subexpressions undefined? (magic ruts)
by Anonymous Monk on Apr 19, 2005 at 15:58 UTC
    Hmm. I though lazy evaluation meant that the value wasn't calculated until needed.
    Indeed. So, if you have:
    result = f(a) * g(b) + h(c);
    and f(a) returns 0, there's no need to call g(). (Or, if you're doing Inf and NaN arithmetic, there's no need to call g() if f(a) returns NaN).
    if the compiler took it upon itself to override my explicit request to call it.
    If you have lazy evaluation, there's no explicit request to call anything!
Re^38: Why is the execution order of subexpressions undefined? (magic ruts)
by Anonymous Monk on Apr 19, 2005 at 15:58 UTC
    What are you talking about? Are you being deliberately obtuse? The other AM already gave you examples of lazy operators which exist (Right Now! Today!) in Perl5. They're called || and &&.

      Yes. They are defined as being lazy. I know they are lazy. I like that they are lazy. But now you want to make math operators lazy too?


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      Lingua non convalesco, consenesco et abolesco.
      Rule 1 has a caveat! -- Who broke the cabal?
        Well, I'm not saying I'm on a crusade to make them lazy. But if they were to made lazy, I'd welcome it. It would speed up some code, and I'm pretty sure I don't have much code that will break.