Augmented assignment (ie. += and friends) for Python!

Michael Hudson mwh21 at cam.ac.uk
Thu May 11 18:41:55 EDT 2000


wtanksle at dolphin.openprojects.net (William Tanksley) writes:

> On 10 May 2000 18:53:22 +0100, Michael Hudson wrote:
> >I thought I might waste some time by having a crack at implementing +=
> >and friends in Python.  I think I know what I want to do on the
> >codegen side, but at the moment that hurdle looks some way off.
> 
> Sounds like fun.

And indeed it was; I think I'm done now (well, the hard bits, anyway).

I have built myself a Python that does this:

Python 1.6a2 (#38, May 11 2000, 18:31:58)  [GCC 2.95.2 19991024 (release)] on linux2
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
Copyright 1995-2000 Corporation for National Research Initiatives (CNRI)
>>> a=range(10)
>>> a[2] *= 4
>>> a[3] -= 4
>>> a
[0, 1, 8, -1, 4, 5, 6, 7, 8, 9]

Cool, huh?

You can read about it and find a patch here:

    http://starship.python.net/crew/mwh/aug-patch.html

Questions, comments, flames, praise, abuse - all welcome.

for-my-next-trick---static-typing-(only-joking)-ly y'rs
Michael

-- 
31. Simplicity does not precede complexity, but follows it. 
     -- Alan Perlis, http://www.cs.yale.edu/~perlis-alan/quotes.html



More information about the Python-list mailing list