[Python-ideas] Null coalescing operators

Stephen J. Turnbull stephen at xemacs.org
Mon Sep 21 18:29:43 CEST 2015

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.

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