Pascal int()

Gordon McMillan gmcm at hypernet.com
Sat Mar 18 17:05:49 CET 2000


Jason Stokes wrote:

[Michal Bozon wants an "inc" method]

> This means that without playing tricks with namespace dictionaries, the best
> you can do is:
> 
> def inc(x);
>     return x+1 # returns a *new* integer object one greater than x
> 
> a = 1
> a = inc(a) # rebinds a to the integer object storing the value "2"
> 
> If, like Smalltalk or Lisp, there was a syntax for passing a name or symbol
> as an argument instead of a reference to an object, it would be possible to
> write a Pascal style inc() function.  Unfortunately despite the previously
> posted mechanism, which is brittle and breaks for non-global names, I cannot
> think how this would be implemented naturally in Python as it stands,
> although a Python god may correct me.

I can assure you that no Python god, archangel, angel, 
seraphim or cherubim would ever write anything but
 a = a + 1



- Gordon




More information about the Python-list mailing list