PEP 308: Yet another syntax proposal.

sismex01 at hebmex.com sismex01 at hebmex.com
Mon Feb 17 10:27:28 EST 2003


> From: John Roth [mailto:johnroth at ameritech.net]
> Sent: Saturday, February 15, 2003 7:20 AM
> 
> There's also an ambiguity with the final <expression>.
> Where does it end? Consider:
> 
> x = when a == b: c + 1 else d + 2
> 
> if the true value fires, is the result c + 1 or c + 1 + 2?
> 
> John Roth
>

Howdy, nice monday.

Well, of *course* the final result is (c+1), and not (c+1+2).
Why? Well, maybe it's just me, but I've got this impression
that the ternary operator should have a very low precedence,
like "or".

For example:

   x = a == b and 10 or 15

The result is obvious, because you "know" that "and" binds
stronger than "or".  Ternary operators are like a dual "or",
so they should have aproximately the same precedence.

This allows all expressions to resolve, before attacking
the if-else part.

But then, maybe that's just me. :-)

-gustavo





More information about the Python-list mailing list