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

DeepBlue DeepBlue at DeepBlue.org
Sun Oct 14 19:47:44 EDT 2001


"Tim Peters" <tim.one at home.com> wrote in message
news:mailman.1003089072.26009.python-list at python.org...
>
>     x = if e1 then e2 else e3 + 1   # SyntaxError
>     x = (if e1 then e2 else e3) + 1 # cool

Much better:
x = if e1 then (e2) else (e3)
note that (e2) and (e3) stand for any operation:
The problem with: x = (if e1 then e2 else e3) + 1 # cool
is that it lacks potential of generalization.
x = if e1 then (e2) else (e3)
does give the user more freedom.

>     x = (if e1 then e2 else e3 + 1) # cool
but not clear.
>     x = if e1 then e2 else e3       # SyntaxError
no reason for error
>     x = (if e1 then e2 else e3)     # cool
shuold be euivalent to above
>     x = if if e1 then e2 else e3 then e4 else e5     # SyntaxError
>     x = (if (if e1 then e2 else e3) then e4 else e5) # cool
But
x = if (if e1 then e2 else e3) then e4 else e5  #  should be cool too
and so
x = (if (if e1 then e2 else e3) then e4 else e5)

with my idea:
x = (if (if e1 then (e2) else (e3)) then (e4) else (e5))
or
x = if (if e1 then (e2) else (e3)) then (e4) else (e5)
should be equivalent.
If the original posting passes Python will have its first confusing moment.
x = if e1 then (e2) else (e3)
and
x = (if e1 then (e2) else (e3))
should be equivalent and they preserve clarity.
DB





More information about the Python-list mailing list