sequence multiplied by -1

Antoon Pardon Antoon.Pardon at rece.vub.ac.be
Fri Oct 1 08:56:52 EDT 2010


On Thu, Sep 30, 2010 at 07:02:40AM -0700, Emile van Sebille wrote:
> On 9/30/2010 5:10 AM Antoon Pardon said...
> >On Sun, Sep 26, 2010 at 03:20:18PM +0000, Grant Edwards wrote:
> >>On 2010-09-26, Paul Rubin<no.email at nospam.invalid>  wrote:
> >>>Steven D'Aprano<steve at REMOVE-THIS-cybersource.com.au>  writes:
> >>>>There's nothing obscure or unintuitive about "spam"*3 = "spamspamspam",
> >>
> >>>Why would it not be ["spam","spam","spam"] or even "ssspppaaammm"?
> >>
> >>Because
> >>
> >>3 * "spam" == "spam" + "spam" + "spam"
> >>
> >>Just like
> >>
> >>3 * 6 = 6 + 6 + 6
> >>
> >>So now I suppose "+" for string concatenation is a bad thing.
> >
> >Well I find it an unfortunate choice. The problem is, that it is not that
> >unusual to want some class to have the possibility of both addition and
> >concatenation. But since we only one symbol for both operations, you will
> >have to loose some consistency over this.
> >
> 
> Which is actually a good thing for a class that wants to have both
> concatenation and addition

Why? What is good about losing consistency? It is in this case necessary
but that doesn't make it good.

Think about the following possibility.

Someone provides you with a library of functions that act on sequences.
They rely on the fact that '+' concatenates.

Someone else provides you with a library of functions that act on
numbers. They rely on the fact that '+' provides addition.

Now however you write your sequence like numbers or number like sequences
one of those libraries will be useless for it.

> -- which would it do with only one
> symbol?

But why limit ourselves to one symbol for different kind of operations,
to begin with?

-- 
Antoon Pardon



More information about the Python-list mailing list