PEP 308: Erik's alternatives list

Roman Suzi rnd at onego.ru
Wed Feb 19 11:29:16 EST 2003


On Wed, 19 Feb 2003, Gerald S. Williams wrote:

> "Erik Max Francis" <max at alcyone.com> wrote:
> > I.  Proposals mentioned in the PEP at some point
> [ ...]
> > 3.  if C: x else: y

I do like
        iif(C, :x, :y)

better in the light of PEP 312 ;-)
 
> I'm starting to really like this one. Basically it's
> just interpreting the if/else statement slightly
> differently when used in an expression context,
> returning the value of the alternative. It gets
> its short-circuiting from the normal semantics
> of the if statement. Short-circuited expressions
> follow ":", just like short-cirtuited statements
> do.
> 
> Think of it this way: "if" is the embodiment of
> two-option short-circuiting.
> 
> This would generalize nicely to switch/case if
> that construct ever makes it into Python.
> 
> -Jerry
> 
> P.S.
> 
> I still think the current FAQ should show an
> alternative that is readable and doesn't need
> disclaimers. The following works for me:
> 
>  def ifelse(x): return x[0]
>  ... ifelse(c and [a] or [b])
> 
> 
> 

Sincerely yours, Roman A.Suzi
-- 
 - Petrozavodsk - Karelia - Russia - mailto:rnd at onego.ru -
 






More information about the Python-list mailing list