sequence multiplied by -1
John Nagle
nagle at animats.com
Mon Oct 4 15:37:44 EDT 2010
On 10/2/2010 8:36 AM, Carl Banks wrote:
> On Oct 1, 9:38 pm, Steven D'Aprano<st... at REMOVE-THIS-
> cybersource.com.au> wrote:
>> If so, then we haven't gained anything, and the only thing that would
>> satisfy such people would be for every function name and operator to be
>> unique -- something which is impossible in practice, even if it were
>> desirable.
>
> That is the ideal, yes, and no, it's not impossible.
>
> I would be satisfied if operators were A) reserved for the most common
> and useful operations, and B) should not be used for more than one
> thing.
The big mistake with "sequence multiplied by number" is that
it's a mixed-mode operation. When overloads are restricted to
requiring the same type on both sides, the various meanings
of the operator are disjoint. That's less confusing.
"numpy" implements array*int, with completely different
semantics than those of sequences.
>>> a = numpy.array([1,2,3])
>>> a*2
array([2, 4, 6])
>>> a*-1
array([-1, -2, -3])
"numpy" gives "+" and "*" their arithmetic meaning.
As an exercise to the reader, what's the result of:
numpy.array([1,2,3]) + [4,5,6]
Concatenate? Add? Raise exception?
John Nagle
More information about the Python-list
mailing list