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

Paul Moore gustav at morpheus.demon.co.uk
Sat Feb 8 18:21:51 EST 2003


Erik Max Francis <max at alcyone.com> writes:

> Guido van Rossum wrote:
>
>> PEP: 308
>> Title: If-then-else expression
>
> I am +1 on the addition of a conditional expression.
>
>>     The proposed syntax is as follows:
>> 
>>         <expression1> if <condition> else <expression2>
>
> +0.8.  I want conditional expressions and will take any form I can get,
> but the condition in the middle does seem a little counterintuitive.

Following on from Andrew Koenig's observations on "interesting aspects
of this discussion", I note a lot of people who are in favour of
conditional expressions are making comments along these lines (ie "I
want conditional expressions and will take any form I can get").

This worries me. I'd like to see a little more concern for the overall
integrity of the Python language.

Actually, if I was feeling perverse, I could argue that the following
comes under the category of "any form I can get":

    (expression1, expression2)[bool(condition)]

Or, if you need evaluation of only one of the expressions:

    (condition and (lambda: expression1) or (lambda: expression2))()

Strangely, you can get these forms now.

Can you qualify exactly what you are willing to accept?

> But bottom line is I'll take whatever I can get.  I want a conditional
> expression in Python.

This position is inconsistent. You don't like the forms that currently
exist. (Don't get me wrong, I don't either - but I am not arguing for
a conditional expression to be added to the language).

Paul.
-- 
This signature intentionally left blank




More information about the Python-list mailing list