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

Erik Max Francis max at alcyone.com
Mon Feb 10 04:32:18 EST 2003


Paul Rubin wrote:

> Erik Max Francis <max at alcyone.com> writes:
>
> > In other words, writing
> >
> >       if C: x else: y
> >
> > as a standalone statement (the Corner Case) is illegal.
> 
> I don't see why that should be illegal, given that there's no doubt
> about what it's supposed to do.  I don't think it's that useful to do
> it, but why treat it specially or make it illegal?

It's not about treating it specially.  On the contrary; it would be
illegal as it stands (parsed as an if statement, and it's not legal to
have the `else:' there, and making the special case of admitting it into
the language doesn't seem worth it.  I'm working from the point of view
of the path of least resistance, here.  Admitting that as legal code
requires parser changes beyond just the implementation of the
conditional operator, since the `if' statement has to look ahead to the
`else:' to see how it's going to get used.

If someone things it's a great idea and does it, hey, fine; like I said,
it's a situation that I'm ambivalent about.  I'm just saying 1. it would
make additing it to the language harder in terms of parser changes and
2. I think there would be greater resistance to writing if...else
constructs on all one line (as a statement) on just general principles.

Again:  Either situation would be fine with me (it's legal, or it's not
legal).  My proposition, which requires the least effort to implement,
is that it be deemed illegal since the `if' starting the statement is
taken to be an if statement and thus the `else:' on the same line is
illegal.  The Corner Case doesn't interest me because I don't have any
interest in using it, and don't see much interest in it in general, or
it being widely used.

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ Yes I'm / Learning from falling / Hard lessons
\__/ Lamya
    Bosskey.net: Quake III Arena / http://www.bosskey.net/q3a/
 A personal guide to Quake III Arena.




More information about the Python-list mailing list