Why does this (not) work?
Erik Max Francis
max at alcyone.com
Wed Aug 20 00:56:47 CEST 2003
"Michael C. Neel" wrote:
> Hmmm, can't say I like what this implies. In one case % is shorthand
> for a sprintf function, the other it's a mathematical expression at
> same level of precedence of * and /. But the sprintf version is
> "granted" the precedence of the mathematical version? What's the
> behind that?
Very, very good logic. Consider the following expression:
left % middle * right
If we are to take your suggestion, and % is to have different precedence
based on whether or not it is being used as a string formatting
operation or as module division, then the precedence will be
left % (middle * right)
(left % middle) * right
depending on the type of `left'. That means that the precedence changes
based on the types of the arguments. That is disastrous in a dynamic
language like Python for both processing and readability, because now it
means the same expression can have widely different semantic meanings
based on their arguments. Having the same operator have different
precedence based on its operands would be disastrous.
Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
__ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
/ \ A wise man never loses anything if he have himself.
More information about the Python-list