For review: PEP 308 - If-then-else expression

Erik Max Francis max at
Sat Feb 8 20:14:15 CET 2003

Evan wrote:

> Here's a totally new direction: let's get rid of the chaining and
> precedence issues, and make an n-way conditional, not a ternary.
> {if cond1: expr1, default}
> {if cond1: expr1, cond2: expr2, default}
> etc.
> Obviously, comma precedence with the braces works the same way as in a
> literal dict.

Both the use of curly braces and commas seem terribly inappropriate
here.  When this is "corrected," you end up with

	(if cond1: expr1 else: default)

or in the more general sense

	(if cond1: expr1 elseif cond2: expr2 else: default)

The former syntax is itself brought up in the PEP "Alternatives"
suggestion and shot down as being "even more confusing because it
resembles the if statement so much."

To backtrack, maybe that isn't a bad idea.  There doesn't see much worry
of parser ambiguities (one can simply require parentheses when and if
they arise).  So all you're doing is providing an alternative form for a
recognized syntax:

	if cond:

and collapsing it into an expression:

	(if cond: expression1 else: expression2)

That really doesn't strike me as so bad.  Particularly if most of the
objections center around overloading the meaning of if, or the
awkwardness of reading the proposed x if p else y structure not reading
left-to-right, maybe this makes sense after all?

 Erik Max Francis / max at /
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ So look into my eyes / I won't tell you lies
\__/ Neneh Cherry
    Official Omega page /
 The official distribution page for the popular Roguelike, Omega.

More information about the Python-list mailing list