Python complaints

Martijn Faassen m.faassen at vet.uu.nl
Wed Dec 1 06:01:06 EST 1999


Will Ware <wware-nospam at world.std.com> wrote:
[snip]
> 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()".

But this would be a method of the 'i' reference (and currently references
can't have methods, only that which is referenced). After all, the current
behavior is this: 

i = 3
j = i
i = i + 1
print i, j # prints 4, 3

The behavior of an 'incr()' method to an integer would mean this:
i = 3
j = i
i.incr()
print i, j # prints 4, 4 (!)

Therefore your behavior should be somekind of 'reference method'. Interesting
concept in its own right perhaps (I just started thinking about it in
this post), but currently not part of Python. This would be a work around:

i = 3
j = i
i = i.incr()
print i, j # prints 4, 3

But i = i + 1 is just as easy to type.

Regards,

Martijn
-- 
History of the 20th Century: WW1, WW2, WW3?
No, WWW -- Could we be going in the right direction?




More information about the Python-list mailing list