[Python-Dev] Adding a conditional expression in Py3.0

Nick Coghlan ncoghlan at gmail.com
Thu Sep 22 00:35:06 CEST 2005


Jim Jewett wrote:
<a very nice summary>
> 
> (3)  What order should the clauses appear?
>     (if test then True else False)
>     (if test1 then Val1 elif test2 Val2 elif test3 Val3 else Val4)
>         + Natural Order
>         - do we need "then"?
>     (True if normal else False)
>     (Val1 if test1 else Val2 if test2 else Val3 if test3 else Val4)
>         + Best order for normal/default conditionals
>         + Best order in general if we weren't used to left-right processing
>         - But we *do* expect left->right almost everywhere except assignments

           + out-of-order evaluation is already used in LC's and GE's
           + declarative style, rather than imperative

To try and make that last point clearer:

   real = (z.real if isinstance(z, ComplexType) else z)

This translates directly into in words as: "Set real to be the real component 
of z if z is a complex number, otherwise set it to be the same as z"

vs.

   real = (if isinstance(z, ComplexType) then z.real else z)

I can't put that into words without changing the order of the elements either 
by re-using the phrasing from above (with the condition between the two 
outcomes), or else describing the statement form instead of the expression 
form by bringing the condition all the way to the front: "If z is a complex 
number, then set real to be the real component of z, otherwise set real to be 
the same as z"

I find it to be like with GE's and LC's - the phrasing works better with the 
expression at the front, because you say basically what you're doing, then you 
put the additional constraints on it (i.e., which iterable is used as the data 
source, and what filtering is applied to the elements of that iterable)

I think I've said enough on this point though, so I'll try to bite my tongue 
until Guido makes a decision. . .

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://boredomandlaziness.blogspot.com


More information about the Python-Dev mailing list