Re: Python has Traps; Does Euphoria have Programming Traps?
- Posted by SDPringle Aug 19, 2013
- 1925 views
This example is now known as the Python Short-Circuit Trap.
When calculating an expression (out-side of a test condition) this is how Euphoria and Python compare:
The Euphoria interpreter evaluates the entire expression; the evaluated result has to be the "correct" result.
In the Python example short-circuit evaluation yields just the first portion of the expression; the answer "looks reasonable" so the correctness of the result is not questioned. The trap is how do you debug a program where "looks reasonable" is not good enough and the "correct" result should be used instead.
This is simply not true,
The reason you get different results is because the syntax is interpreted differently. The expression 0 <= 5 <= 9 in Python is equivalent to (0 <= 5) and (5 <= 9). Often this notation is used as a short form in Mathematics courses.
It is not that it evaluates 0 <= 5 and quits, instead the Python interpreter sees that it is true and then evaluates 5 <= 9 to ensure the whole expression is true. Ofcourse it is, so it will return true. No short circuit here. In the other case, 0 <= -5 evaluates to false. So there is no need to evaluate -5 <= 9. This is where short circuit evaluation comes into play.
For example: 0 <= 5 <= 3 in Python doesn't evaluate to True, even though 0 <= 5 evaluates to True.