David A. Black wrote: > Hi -- > > On Wed, 18 Aug 2004, Brian Palmer wrote: > > > >> So yeah, the whole "on_#{arg}= a" thing is a hack, but += doesn't >> behave as I would expect when used after a method. I would think it >> would call the method first, and then call += on its return value. >> But it calls the method, calls + on its return value, then calls the >> method= version of the method. >> > > > The way you're describing can't really work, though; you'd end up with > the problem of altering immutable values (the same thing that has led > Matz not to have a ++ operator): > > obj.x = 1 > obj.x += 1 # would resolve to: 1 += 1, which is: 1 = 1 + 1 > > The syntactic sugar transformation (a += b to a = a + b) has to happen > before anything else happens that could turn the lhs into a > non-l-value. > > > David > > That's true. I figured there was a reason for it, just wasn't sure what. So it couldn't be set up to simply throw a run-time error exception if you try to alter an immutable value in this way? Or it could, but it would take a lot of time/make things slower? Just trying to understand things better... Brian