PEP308: Yet another syntax proposal

holger krekel pyth at devel.trillke.net
Mon Feb 10 13:41:54 EST 2003


Dave Brueck wrote:
> On Mon, 10 Feb 2003, Aahz wrote:
> 
> > In article <YUP1a.3080$SB2.242 at nwrddc03.gnilink.net>,
> > Raymond Hettinger <python at rcn.com> wrote:
> > >
> > >I suggest:
> > >
> > >    cond  ??  val1  ||  val2
> >
> > +0.5
> >
> > I still have yet to see a clear explanation of why short-circuit is
> > necessary
> 
> Short-circuit evaluation is never "necessary" in _any_ language - it's
> just very, very useful sometimes. Python's 'and' operator doesn't _have_
> to be a short-circuit operator, but it's far more useful because it is.
> 
> > and therefore iif() unreasonable.
> 
> Several of the previous examples have already illustrated this:
> 
> z = iif(x, x.getPref(), 'Not specified')
> 
> is broken without short-circuiting.

yes, but it is easily written with an and-expression

  z = not x and 'Not specified' or x.getPref()

and a ternary op would simply add another possibility. 
A new ternary op can't be so good as to wipe out the
need (and all the existing code) for and/or behaviour.
In which case you have to learn two constructs. 

Now if we had

    z = x.getPref() except AttributeError: 'Not specified'

that might add something which we didn't have before 
(in an expression). 

    holger





More information about the Python-list mailing list