PEP 308 - ternary operator

Michele Simionato mis6 at pitt.edu
Wed Feb 12 16:17:35 CET 2003


"Raymond Hettinger" <vze4rx4y at verizon.net> wrote in message news:<Cld2a.12687$wH5.7856 at nwrddc04.gnilink.net>...
> "Erik Max Francis" <max at alcyone.com> wrote in message
> news:3E48B45F.A7E2881A at alcyone.com...
> > Jim Jinkins wrote:
> >
> > > My preference for an immediate-if operator is the traditional '?' from
> > > C:
> > >
> > >     cond ? expr1 : expr2
>  ...
> > > If this is not acceptable my second choice is a functional form:
> > >     iif(cond, expr1, expr2)
> > >
> > > This is not a function, it is a built-in macro.
> >
> > Both of these forms have been explicitly rejected by the BDFL, although
> > for different reasons; check the current state of the PEP.
> 
> Actually, he's wavering on both.
> However, the second form would
> be implemented with a keyword
> instead of a macro, but the effect
> would be the same.  Also, "iif"
> looks like a typo to him, so it
> would have to be "cond", "test",
> or some such.
> 
> 
> Raymond Hettinger
> 

I am not so hot on the built-in function/macro, however I have an
idea:
why not the syntax "__if__(C,x,y)" ?

The underscores would suggest that this is a special "if", which
actually
is not a function but a short-circuiting macro. The minus is that 
special methods are not short-circuiting, therefore this could be
confusing. Maybe

_if_(C,x,y)

is better.
I like to reuse "if" here, since there absolutey no risk of confusion
with the "if" statement and the underscores suggest that something
special is going on.

Just my $0.02,

                                                        Michele




More information about the Python-list mailing list