Python complaints

James Logajan JamesL at Lugoj.Com
Wed Dec 1 01:15:37 EST 1999


Will Ware wrote:
> 
> Will Ware wrote:
> > I find myself grumbling about having to type "x = x + 1". The really
> > clean thing to do, given that integers are objects, would be to define
> > increment and decrement methods, so you'd type something like "i.incr()".
> 
> Jesse D. Sightler (jsight at mindspring.com) wrote:
> > Wouldn't this be impossible, since Integers are also immutable?  So, eg,
> > i.incr() could only return an incremented version of i, but not actually
> > increment i?
> 
> Right, this is what Gordon was pointing out. A "++" method could not
> magically reach out of its object, find the "i" variable, and bind it
> to the incremented value. Something like this could be accomplished
> by tinkering with Python's parser, but that wouldn't be a great idea.
> A lot of work for something that would never find wide acceptance.

An alternate view (possibly incorrect, but I suspect it is close to
correct):

The "++" method doesn't belong to the underlying object (e.g. the number 3
or the string "xyzzy"), but to the reference "i". After all, at a certain
point in execution the "i" may reference any possible value. The execution
frame resolves the meaning of "i++" first by looking at the *class* of
object referenced by "i" _at that moment_ and if it then makes sense
(exception if not) uses the currently referenced object to find the next
object to be referenced.

I think any OO execution model that can't account for something as basic as
assignment may lead to erroneous conclusions about what can and can not be
considered valid operations. And this is what it boils down to after all.
Maybe I'm missing something, (or maybe others are), but I can't see how
adding the "++" operator suddenly makes numbers mutable. No one is asking
for 2 to become 3, merely that *REFERENCES* be mutable. You couldn't
accomplish a whole hell of a lot of computation if references always pointed
to the same values for all time!

This message delivered on behalf of the Mutable Reference Liberation Front!
Long live references!




More information about the Python-list mailing list