conditional expressions (RE: Loop-and-a-half (Re: Curious assignment behaviour))

John Roth johnroth at ameritech.net
Mon Oct 15 14:40:07 EDT 2001


"Tim Peters" <tim.one at home.com> wrote in message
news:mailman.1003089072.26009.python-list at python.org...
> [Tim]
> > If people sign off on taking "then" as a new keyword, I think
> > the chances are good that we could get
> >
> >     x = if e1 then e2 else e3
> >
> > into 2.2b1.  That's the only obvious spelling, hence the only
> > truly Pythonic way to spell it.  Other languages spelling it that
> > way range from Algol-60 (Guido's first intense language affair) to
> > Haskell.
>
> [Paul Rubin, among others of similar mind]
> > This sounds fine to me.
>
> Alas, it didn't to Python's parser -- one-token lookahead isn't enough to
> distinguish
>
>     if 1:
>
> from
>
>     if 1 then 2 else 3
>

Huh? The purpose of the new syntax is to have a conditional
facility within an expression. If a new line begins with the keyword
'if', then that is a statement. A conditional if only makes sense _inside_
an expression, hence it doesn't look like there is an issue.

A bigger issue from a usability standpoint is the lack of a
clear end to the scope of a given 'if', leading to the infamous
dangling 'else' problem.

John Roth





More information about the Python-list mailing list