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

No. Logical operators short circuit, but you do not do associative and communicative math with logical operators.


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^35: Why is the execution order of subexpressions undefined? (magic ruts)
  • Download Code

Replies are listed 'Best First'.
Re^36: Why is the execution order of subexpressions undefined? (magic ruts)
by Anonymous Monk on Apr 19, 2005 at 15:30 UTC
    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.

      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 &&.