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

That's not my point. My point is that there are already operators where EXPR1 OP EXPR2 may cause one of the expression to not be evaluation, and people don't find that strange. Or inconvenient.

And in languages with lazy evaluation, this is common.

  • Comment on Re^36: Why is the execution order of subexpressions undefined? (magic ruts)

Replies are listed 'Best First'.
Re^37: Why is the execution order of subexpressions undefined? (magic ruts)
by BrowserUk (Patriarch) on Apr 19, 2005 at 15:45 UTC

    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?
      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!
      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?