Re: Python has Traps; Does Euphoria have Programming Traps?

new topic     » goto parent     » topic index » view thread      » older message » newer message

This example is now known as the Python Short-Circuit Trap.

A short-circuit evaluation occurs "when the first reasonable result for an expression is yielded." This is an optimization that saves extra calculations when evaluating expressions and is common in many languages.

Python is an example of a language where short-circuit evaluation is performed all of the time. In Python you can get an unexpected result.

In Euphoria short-circuit evaluation is only performed inside a test condition ( conditional structures, loop structures ) containing these keywords: and , or . This means that Euphoria short-circuit evaluation produces the "result you expect."

When calculating an expression (out-side of a test condition) this is how Euphoria and Python compare:

http://euphoria.derekparnell.id.au/short-circuit/Short-Python.png

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.

So it looks like Euphoria has no traps but Python has many traps.



Special thanks to Derek Parnell

He has provided me with the means of adding diagrams to the forum and the wiki.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu