PATCH: Augmented assignment

Thomas Wouters thomas at xs4all.net
Fri Jun 9 16:01:52 EDT 2000


On Fri, Jun 09, 2000 at 07:16:28PM +0000, Huaiyu Zhu wrote:

> >>As promised, here is my patch to add augmented assignment (+=, -= and
> >>family) to Python. It's still Work In Progress, and probably requires a
> >>rewrite of some magnitude before Guido will accept it.

> Greate!  I'll use them in the MatPy package as well.

Cool! Because I'm sure that helps the acceptance of the patch :)

> BTW, maybe __add_eq__ would be a better name than __add_ad__, as it
> describes the symbols instead of their meaning.

I thought about this, but decided 'eq' isn't the right word. If we go and
describe the symbols, it should be '__plus_eq__'. The __hooks__ all have a
name descriptive of their numerical function, so I would personally favor
'__inplace_add__'. It might be a bit long, but it's fairly hard to get more
descriptive. The only hurdle might be explaining what 'inplace' stands for,
but the concept has been obvious to me for too long to make a useful
statement about that ;-)

If '__inplace_add__' is too long, perhaps '__iadd__' is better: it
emphasizes that the hook, like __radd__, is a 'specialized' version of
__add__.

Also, using '__add_eq__' might suggest to people that it is also called for

x = x + 1

as it also contains both the 'add' operator and the 'eq' sight ;)
But Guido suggested __add_ad__ in his latest posting on this subject, and it
is ultimately his choice. If he comes up with a better name, or changes his
mind in favor of whatever suggestion whoever made, it's a simple case of
search-and-replace to fix it, anyway ;)

-- 
Thomas Wouters <thomas at xs4all.net>

Hi! I'm a .signature virus! copy me into your .signature file to help me spread!




More information about the Python-list mailing list