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

Erik Max Francis max at alcyone.com
Sun Feb 9 22:31:57 EST 2003


Paul Rubin wrote:

> It's my favorite too, at this point.

And, as I pointed out when I first suggested it (though later found out
that I was not the first) -- and which Andrew Koenig reminded me (again,
independently) of in email -- it easily lends itself quite easily to
multiway extension:

	if C1: x elif C2: y else: z

The only real complaint I can see about it is that it could in some
circumstances take a little lookahead to make sure that what you've got
is an expression, not a statement, so maybe the best solution there is
to require parentheses:

	(if C: x else: y)
	(if C1: x elif C2: y else: z)

There's no way an `if' keyword preceded by an open parenthesis could be
an if statement, so that separates the two really easily and really
early on  I don't know enough about the parser internals to know whether
this would be a distinct benefit.  If such a structure were adopted, I
can't see myself _not_ using parentheses to set it off anyway.

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ Patiently, I'm still / Holding out until
\__/ Sandra St. Victor
    Church / http://www.alcyone.com/pyos/church/
 A lambda calculus explorer in Python.




More information about the Python-list mailing list