A Summary: Expression-Assignments. (Very Long)
Evan Simpson
evan at tokenexchange.com
Fri May 14 14:21:17 EDT 1999
Michael P. Reilly wrote:
[snip]
> Since assignment works on references to variables, this can lead to some
> complications. Also, there are a good number of ambiguities that result
> from working with overloaded objects.
[snip]
> x = 1 # simple assignment
> x += 2 # simple: x = ( x + 2 )
> x += B() # should x now result in an integer or an instance of B?
Some better examples of ambiguity:
(x, y, z) += 1
# (x, y, z) = (x, y, z) + 1 is meaningless. How about (x, y, z) = (x + 1, y
+ 1, z + 1)?
(x, y, z) += (1, 2, 3)
# oops. Here people might expect (x, y, z) = (x+1, y+2, z+3) instead.
(spam, eggs) += x += "huh?"
# What could this mean? It looks funky.
x += y *= z <<= 2
# Aaeeiii!
Suppose we cut down "+=" style statements by forbidding these cases. Only
allow simple LHS += RHS constructions. Now we have a heap of statements
roughly similar to "=", but obeying different rules. Ugh.
Of course, we now have a way to make "setadd(x, 1)" mean "x = x + 1".
bytecodehacks-to-the-rescue-ly y'rs
Evan Simpson
More information about the Python-list
mailing list