[Python-ideas] Null coalescing operators
MRAB
python at mrabarnett.plus.com
Mon Sep 21 19:13:19 CEST 2015
On 2015-09-21 17:29, Stephen J. Turnbull wrote:
> Andrew Barnert writes:
> > On Sep 21, 2015, at 01:48, Stephen J. Turnbull <stephen at xemacs.org> wrote:
> >
> > >>>>> retries = default else cls.DEFAULT
> > >
> > > I kinda like this if-less else syntax for the symmetry with else-less
> > > if.
> >
> > How do you parse this:
> >
> > a if b else c else d
> >
> > Feel free to answer either as a human reader or as CPython's LL(1)
> > parser.
>
> I don't know what an LL(1) parser could do offhand. As a human, I
> would parse that greedily as (a if b else c) else d.
>
'else' is being used like 'or', except when it belongs to 'if'.
I can't see a way of handling that.
It would result in a syntax error.
> But the point's actually moot, as I'm -1 on the "??" operator in any
> form in favor of the explicit "a if a is not None else b" existing
> syntax. And to be honest, the fact that a truly symmetric "if-less
> else" would have "or" semantics, not "??" semantics, bothers me more
> than the technical issue of whether anybody could actually parse it.
>
More information about the Python-ideas
mailing list