For review: PEP 308 - If-then-else expression

Carlos Ribeiro cribeiro at mail.inet.com.br
Fri Feb 7 16:37:43 EST 2003


On Friday 07 February 2003 07:05 pm, Harvey Thomas wrote:
> What about a built-in function?
>
> iff(<condition>, <trueresult>, falseresult) which returns <trueresult> if
> <condition> is true, otherwise returns <falseresult
>
> The flow is left to right (more or less), it's similar to constructs in
> other languages.


Functions evaluate their arguments at call time; in this case, it means that 
<falseresult> will be evaluated even if the <condition> is true. For simple 
arguments it means nothing, but what if <falseresult> is a function that 
should only be evaluated if <condition> is false?

There is a workaround for this, that is to have the so-called lazy evaluation 
- in this mode, the arguments will only be evaluated when needed. However, 
this is not supportted in Python, and I am wondering if Guido would like to 
hear about it.


Carlos Ribeiro
cribeiro at mail.inet.com.br





More information about the Python-list mailing list