PEP 308: Alternative conditional operator forms

David Gausebeck gausebec-spam at paypal.com
Mon Feb 10 01:27:15 EST 2003


>> The reason the : makes sense for me is that the syntax here is
>> essentially the same as for 'if', except that this is an expression.
>> To make it even more analogous, it could be
>> 
>> ifelse C: x else: y
>	...
>> Why add a new keyword ('otherwise') when an existing one fits
>> perfectly and causes no conflicts?  'else' in this context seems like
>> a no-brainer.
>
>I'm going to turn that one right around on you.  Why add the new keyword
>`ifelse'?  Why not use `if'?

Yes, that's the obvious responding question :)  Which is why I worded
my statement as I did.  The problem with using 'if' here is that it
conflicts with the current use of the keyword 'if'.

Or at least I believe that's the case... there's some discussion going
on about that right now in the main PEP thread.  If it turns out that
the interpreter can nicely support

lval = if C: x else: y

then I'd be perfectly happy with it.  My support for an alternate
keyword is based on the assumption that the above syntax can't work.

hmm... looking at that, it seems that the interpreter would have
enough context by the time it gets to the 'if' to know if it needs to
be an expression or not.  If the 'if' is an rvalue (function arg, list
element, etc.) then it's an if-expression, otherwise it's a normal
'if'.

-Dave




More information about the Python-list mailing list