Another conditional expression candidate (PEP 308)

Greg Brunet gbrunet at nospamsempersoft.com
Mon Feb 10 12:44:19 EST 2003


"Evan" <evan at 4-am.com> wrote in message
news:RnO1a.12380$yn1.923330 at twister.austin.rr.com...
> Andrew Koenig wrote:
> > I don't see any reason for the parens to be mandatory.
>
> It eliminates the Corner Case, precedence issues, and Alan Daniels
> objection elsewhere in this thread.
>
.
.
.
> See?  Also, parse this for me (assuming that those who also want else:
> to be optional win):
>
> x = if c1: e1 elif c2: if c3: e3 else: e4
>
> Now parse this:
>
> x = (if c1: e1 elif c2: (if c3: e3) else: e4)
>
> My point is that if Guido is going to agree to add this controversial
> new feature to Python, the result should be absolutely
> no-thought-required readable and consistent.  Nothing optional, apart
> from the inherent n-way optionality of the elif: clauses.  No
precedence
> questions.  No Corner Case.  Dead simple.


As a Python newbie, I like this candidate the best of all those
presented so far.  I can figure out what it's doing the very first time
without having to have it explained to me, and as you show in your
examples, the parenthesis continue to make the precedence very clear.
Now one thing I'm not sure of from your last example (above), is that I
thought you said that the "else:" clause was mandatory, but it's not
present for the (if c3: e3) expression.  Also, from your examples, is it
correct to assume that the "elif:" clause is NOT required?


-- 
Greg





More information about the Python-list mailing list