In defence of the two-namespace rule
Quinn Dunkan
quinn at myxo.ugcs.caltech.edu
Sun Jan 23 15:37:41 EST 2000
On Sun, 23 Jan 2000 08:37:14 -0500, Colin J. Williams <cjw at connection.com>
wrote:
>> >>> map(add(5), range(5))
>> [5, 6, 7, 8, 9]
>>
>Wouldn't it be nice if we could write this as:
>
> 5 + range(5) or
> range(5) + 5?
>
>Are we not complicating things by using '+' to mean addition in
>most cases but catenation in the case of a list?
No, we _are_ complicating things in that case :) This sort of thing, while
not appropriate for lists, does make sense for (at least my definition of)
vectors, where you want "vector promotion":
>>> apply(Vec, range(5)) + 5
<5, 6, 7, 8, 9>
This is where you define __add__ and __radd__.
More information about the Python-list
mailing list