Re: sequence multiplied by -1

2010-10-06 Thread Albert van der Horst
In article <4ca6bd15$0$2$c3e8...@news.astraweb.com>, Steven D'Aprano wrote: >On Fri, 01 Oct 2010 14:56:52 +0200, Antoon Pardon wrote: > >> Think about the following possibility. >> >> Someone provides you with a library of functions that act on sequences. >> They rely on the fact that '+' con

Re: sequence multiplied by -1

2010-10-04 Thread Carl Banks
On Oct 4, 3:09 pm, Gregory Ewing wrote: > Carl Banks wrote: > > Numpy uses + for elementwise addition, and a function > > called concatenate for concatenation.  If Python lists used a separate > > concatenation operator, then Numpy arrays could use that for > > concatenation. > > Actually it could

Re: sequence multiplied by -1

2010-10-04 Thread Gregory Ewing
Carl Banks wrote: Numpy uses + for elementwise addition, and a function called concatenate for concatenation. If Python lists used a separate concatenation operator, then Numpy arrays could use that for concatenation. Actually it couldn't, except for the special case of concatenating along the

Re: sequence multiplied by -1

2010-10-04 Thread Carl Banks
On Oct 4, 9:14 am, Ethan Furman wrote: > Antoon Pardon wrote: > > Suppose you write your class so that '+' will provide addition and > > you provide a method concat to concatenate. Now no matter how usefull > > the sequence library would be for you, you can't use it. You will > > have to rewrite t

Re: sequence multiplied by -1

2010-10-04 Thread John Nagle
On 10/2/2010 8:36 AM, Carl Banks wrote: On Oct 1, 9:38 pm, Steven D'Aprano 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 de

Re: sequence multiplied by -1

2010-10-04 Thread Ethan Furman
Antoon Pardon wrote: Suppose you write your class so that '+' will provide addition and you provide a method concat to concatenate. Now no matter how usefull the sequence library would be for you, you can't use it. You will have to rewrite those function you need, in terms of a concat method inst

Re: sequence multiplied by -1

2010-10-04 Thread Antoon Pardon
On Sat, Oct 02, 2010 at 05:03:17AM +, Steven D'Aprano wrote: > On Fri, 01 Oct 2010 14:56:52 +0200, Antoon Pardon wrote: > > > Think about the following possibility. > > > > Someone provides you with a library of functions that act on sequences. > > They rely on the fact that '+' concatenates.

Re: sequence multiplied by -1

2010-10-04 Thread Antoon Pardon
On Fri, Oct 01, 2010 at 09:44:34AM -0700, Emile van Sebille wrote: > On 10/1/2010 5:56 AM Antoon Pardon said... > > >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

Re: sequence multiplied by -1

2010-10-04 Thread Antoon Pardon
On Sat, Oct 02, 2010 at 04:38:16AM +, Steven D'Aprano wrote: > On Fri, 01 Oct 2010 10:24:11 -0700, Carl Banks wrote: > > > On Sep 26, 8:20 am, Grant Edwards wrote: > [..] > >> So now I suppose "+" for string concatenation is a bad thing. > > > > Yes. It's not the end of the world, but a sep

Re: sequence multiplied by -1

2010-10-03 Thread Bruno Desthuilliers
Stefan Schwarzer a écrit : > One could argue that using L[::-1] isn't "obvious" It *is* obvious - once you've learned slicing. "obvious" doesn't mean you shouldn't bother reading the FineManual. -- http://mail.python.org/mailman/listinfo/python-list

Re: sequence multiplied by -1

2010-10-03 Thread Mel
Seebs wrote: > On 2010-10-03, Steven D'Aprano > wrote: >> On Sat, 02 Oct 2010 12:50:02 -0700, Dennis Lee Bieber wrote: >>> Well... We could maybe borrow from REXX... and >>> use || for concatenation. > >>|| for concatenation? What's the connection between the pipe character >> and c

Re: sequence multiplied by -1

2010-10-02 Thread Seebs
On 2010-10-03, Steven D'Aprano wrote: > On Sat, 02 Oct 2010 12:50:02 -0700, Dennis Lee Bieber wrote: >> Well... We could maybe borrow from REXX... and >> use || for concatenation. >|| for concatenation? What's the connection between the pipe character > and concatenation? Th

Re: sequence multiplied by -1

2010-10-02 Thread Steven D'Aprano
On Sat, 02 Oct 2010 12:50:02 -0700, Dennis Lee Bieber wrote: > Well... We could maybe borrow from REXX... and > use || for concatenation. || for concatenation? What's the connection between the pipe character and concatenation? I realise that, ultimately, every symbol was

Re: sequence multiplied by -1

2010-10-02 Thread Steven D'Aprano
On Sat, 02 Oct 2010 14:09:15 -0700, geremy condra wrote: > I'd actually love the ability to overload this, although I'm not sold on > the itertools.chain thing. To me it looks a lot like the 'is isomorphic' > operator from graph theory, and we could really use that in Graphine. You can overload t

Re: sequence multiplied by -1

2010-10-02 Thread Steven D'Aprano
On Sat, 02 Oct 2010 14:12:39 -0700, Dennis Lee Bieber wrote: > I'd prefer to see it used for floating point comparison in the two > character: > x ~= y > though one might need to set up some system parameter to define what the > permissible delta would be... > > sys.fl

Re: sequence multiplied by -1

2010-10-02 Thread MRAB
On 02/10/2010 22:12, Dennis Lee Bieber wrote: On Sat, 02 Oct 2010 21:24:19 +0100, MRAB declaimed the following in gmane.comp.python.general: How about "~", which is currently has only a unary form: >>> "foo" ~ "bar" 'foobar' >>> [1, 2, 3] ~ [4, 5, 6] [1, 2, 3, 4, 5, 6] Think of it as me

Re: sequence multiplied by -1

2010-10-02 Thread geremy condra
On Sat, Oct 2, 2010 at 1:24 PM, MRAB wrote: > On 02/10/2010 20:50, Dennis Lee Bieber wrote: >> >> On 02 Oct 2010 04:38:16 GMT, Steven D'Aprano >>  declaimed the following in >> gmane.comp.python.general: >> >> >>> If so, then we haven't gained anything, and the only thing that would >>> satisfy s

Re: sequence multiplied by -1

2010-10-02 Thread MRAB
On 02/10/2010 20:50, Dennis Lee Bieber wrote: On 02 Oct 2010 04:38:16 GMT, Steven D'Aprano declaimed the following in gmane.comp.python.general: 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 uniqu

Re: sequence multiplied by -1

2010-10-02 Thread Carl Banks
On Oct 1, 9:38 pm, Steven D'Aprano 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, a

Re: sequence multiplied by -1

2010-10-01 Thread Steven D'Aprano
On Fri, 01 Oct 2010 14:56:52 +0200, Antoon Pardon wrote: > 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 > num

Re: sequence multiplied by -1

2010-10-01 Thread Steven D'Aprano
On Fri, 01 Oct 2010 10:24:11 -0700, Carl Banks wrote: > On Sep 26, 8:20 am, Grant Edwards wrote: [..] >> So now I suppose "+" for string concatenation is a bad thing. > > Yes. It's not the end of the world, but a separate concatenation > operator would have been better. Then there's no temptat

Re: sequence multiplied by -1

2010-10-01 Thread Carl Banks
On Sep 26, 8:20 am, Grant Edwards wrote: > On 2010-09-26, Paul Rubin wrote: > > > Steven D'Aprano 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" + "sp

Re: sequence multiplied by -1

2010-10-01 Thread Emile van Sebille
On 10/1/2010 9:44 AM Emile van Sebille said... On 10/1/2010 5:56 AM Antoon Pardon said... 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

Re: sequence multiplied by -1

2010-10-01 Thread Emile van Sebille
On 10/1/2010 5:56 AM Antoon Pardon said... 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. But you

Re: sequence multiplied by -1

2010-10-01 Thread Antoon Pardon
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 +, Grant Edwards wrote: > >>On 2010-09-26, Paul Rubin wrote: > >>>Steven D'Aprano writes: > There's nothing obscure or unintuitive about "s

Re: sequence multiplied by -1

2010-09-30 Thread Emile van Sebille
On 9/30/2010 5:10 AM Antoon Pardon said... On Sun, Sep 26, 2010 at 03:20:18PM +, Grant Edwards wrote: On 2010-09-26, Paul Rubin wrote: Steven D'Aprano writes: There's nothing obscure or unintuitive about "spam"*3 = "spamspamspam", Why would it not be ["spam","spam","spam"] or even "ss

Re: sequence multiplied by -1

2010-09-30 Thread Antoon Pardon
On Sun, Sep 26, 2010 at 03:20:18PM +, Grant Edwards wrote: > On 2010-09-26, Paul Rubin wrote: > > Steven D'Aprano writes: > >> There's nothing obscure or unintuitive about "spam"*3 = "spamspamspam", > > > Why would it not be ["spam","spam","spam"] or even "ssspppaaammm"? > > Because > >

Re: sequence multiplied by -1

2010-09-29 Thread Seebs
On 2010-09-29, Lawrence D'Oliveiro wrote: > In message , Seebs wrote: >> Helps, perhaps, that I got exposed to group theory early enough to be used >> to redefining + and * to be any two operations which have interesting >> properties ... > But groups only have one such operation; it???s rings an

Re: sequence multiplied by -1

2010-09-29 Thread Lawrence D'Oliveiro
In message , Seebs wrote: > Helps, perhaps, that I got exposed to group theory early enough to be used > to redefining + and * to be any two operations which have interesting > properties ... But groups only have one such operation; it’s rings and fields (and number systems) that have two. -- h

Re: sequence multiplied by -1

2010-09-26 Thread Steven D'Aprano
On Sun, 26 Sep 2010 09:30:08 +, Seebs wrote: >> There's nothing obscure or unintuitive about "spam"*3 = "spamspamspam", >> and the fact that it doesn't do the same thing as int("spam")*3 is a >> foolish argument. > > The languages in which it's surprising are mostly things like perl, > where

Re: sequence multiplied by -1

2010-09-26 Thread Steven D'Aprano
On Sun, 26 Sep 2010 01:16:49 -0700, Paul Rubin wrote: > Steven D'Aprano writes: >> There's nothing obscure or unintuitive about "spam"*3 = "spamspamspam", > Why would it not be ["spam","spam","spam"] or even "ssspppaaammm"? The first one would be a reasonable design choice, although less useful

Re: sequence multiplied by -1

2010-09-26 Thread Arnaud Delobelle
Paul Rubin writes: > Seebs writes: >> * It seems clear that, given two sequences x and y, "x + y" ought to >> be the concatenation of these sequences. >>... >> Helps, perhaps, that I got exposed to group theory early enough to be used >> to redefining + and * to be any two operations which hav

Re: sequence multiplied by -1

2010-09-26 Thread John Nagle
On 9/26/2010 1:16 AM, Paul Rubin wrote: Steven D'Aprano writes: There's nothing obscure or unintuitive about "spam"*3 = "spamspamspam", Why would it not be ["spam","spam","spam"] or even "ssspppaaammm"? Should "spam"*2.5 be "spamspamsp"? Should "spam"-"a" be "spm"? What about "spamspam"-"a"?

Re: sequence multiplied by -1

2010-09-26 Thread Mel
Grant Edwards wrote: > On 2010-09-26, Paul Rubin wrote: >> Steven D'Aprano 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" > > Ju

Re: sequence multiplied by -1

2010-09-26 Thread Grant Edwards
On 2010-09-26, Paul Rubin wrote: > Steven D'Aprano 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 su

Re: sequence multiplied by -1

2010-09-26 Thread BartC
meaningful symantics. Simply put, a sequence multiplied by -1 can give a reversed sequence. Then for any sequence "seq", and integer n>0, we can have "seq * -n" producing "(seq * -1) * n". Any thoughts? Gimmicky. Best to define multiplication only by unsign

Re: sequence multiplied by -1

2010-09-26 Thread Ian
On 26/09/2010 07:27, Steven D'Aprano wrote: I'm surprised that you think that you should be able to apply arbitrary mathematical operations to strings *before* turning them into an int and still get sensible results. That boggles my mind. You clearly have not been "spoiled rotten" by php.

Re: sequence multiplied by -1

2010-09-26 Thread Paul Rubin
Seebs writes: > * It seems clear that, given two sequences x and y, "x + y" ought to > be the concatenation of these sequences. >... > Helps, perhaps, that I got exposed to group theory early enough to be used > to redefining + and * to be any two operations which have interesting > properties*.

Re: sequence multiplied by -1

2010-09-26 Thread Seebs
On 2010-09-26, Steven D'Aprano wrote: > On Sat, 25 Sep 2010 23:46:57 -0700, Paul Rubin wrote: >> I think the idea is you should not be able to do mathematical operations >> on strings, and if you try to do one, Python should raise an exception, >> rather than using hokey analogies to guess at what

Re: sequence multiplied by -1

2010-09-26 Thread Paul Rubin
Steven D'Aprano writes: > There's nothing obscure or unintuitive about "spam"*3 = "spamspamspam", Why would it not be ["spam","spam","spam"] or even "ssspppaaammm"? Should "spam"*2.5 be "spamspamsp"? Should "spam"-"a" be "spm"? What about "spamspam"-"a"? And what about "spam"/2? "sp" be an ok

Re: sequence multiplied by -1

2010-09-26 Thread Steven D'Aprano
On Sat, 25 Sep 2010 23:46:57 -0700, Paul Rubin wrote: > Steven D'Aprano writes: >> I'm surprised that you think that you should be able to apply arbitrary >> mathematical operations to strings *before* turning them into an int >> and still get sensible results. That boggles my mind. > > I think

Re: sequence multiplied by -1

2010-09-25 Thread Paul Rubin
Steven D'Aprano writes: > I'm surprised that you think that you should be able to apply > arbitrary mathematical operations to strings *before* turning them > into an int and still get sensible results. That boggles my mind. I think the idea is you should not be able to do mathematical operations

Re: sequence multiplied by -1

2010-09-25 Thread Steven D'Aprano
On Sat, 25 Sep 2010 22:08:54 -0700, John Nagle wrote: > On 9/25/2010 4:45 AM, Thomas Jollans wrote: >> On Saturday 25 September 2010, it occurred to Yingjie Lan to exclaim: >>> Hi, >>> >>> I noticed that in python3k, multiplying a sequence by a negative >>> integer is the same as multiplying it by

Re: sequence multiplied by -1

2010-09-25 Thread John Nagle
On 9/25/2010 4:45 AM, Thomas Jollans wrote: On Saturday 25 September 2010, it occurred to Yingjie Lan to exclaim: Hi, I noticed that in python3k, multiplying a sequence by a negative integer is the same as multiplying it by 0, and the result is an empty sequence. It seems to me that there is a

Re: sequence multiplied by -1

2010-09-25 Thread Yingjie Lan
Hi all, Thanks for considering this proposal seriously and all your discussions shed light on the pro's and cons (well, more cons than pros, to be honest). It occurrs to me that this proposal is not a sound one, for the reasons already well documented in this thread, which I need not repeat.

Re: sequence multiplied by -1

2010-09-25 Thread Steven D'Aprano
On Sat, 25 Sep 2010 06:54:36 -0700, Yingjie Lan wrote: > For the rule above, how about the > case to reverse and multiply: > L*-3 #L reversed and repeated three times > > v.s. > L[::-1]*3 #L reversed and repeated three times > > The first one is simpler (4 chars v.s. 9 chars). I thou

Re: sequence multiplied by -1

2010-09-25 Thread Steven D'Aprano
d. Since lists of negative length don't exist, we're free to set the invariance to something which has a less restrictive domain and is more useful than raising an exception: for every list l and integer n: len(l*n) == len(l)*max(0, n) >> Simply put, a sequence multiplied by -

Re: sequence multiplied by -1

2010-09-25 Thread Arnaud Delobelle
On 25 Sep, 09:22, Yingjie Lan wrote: > Hi, > > I noticed that in python3k, multiplying a sequence by a negative integer is > the same as multiplying it by 0, and the result is an empty sequence. It > seems to me that there is a more meaningful symantics. > > Simply put, a s

Re: sequence multiplied by -1

2010-09-25 Thread Stefan Schwarzer
Hi Terry, On 2010-09-25 19:24, Terry Reedy wrote: > On 9/25/2010 4:22 AM, Yingjie Lan wrote: > There is already a builtin reversed() function whose output can be > multiplied. Seemingly, it can't: $ python Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) [GCC 4.4.3] on linux2 Type "help

Re: sequence multiplied by -1

2010-09-25 Thread Emile van Sebille
On 9/25/2010 10:24 AM Terry Reedy said... On 9/25/2010 4:22 AM, Yingjie Lan wrote: I noticed that in python3k, multiplying a sequence by a negative integer is the same as multiplying it by 0, and the result is an empty sequence. This is explicitly documented: "Values of n less than 0 are treat

Re: sequence multiplied by -1

2010-09-25 Thread Terry Reedy
empty sequence of the same type as s).) I would have made this raise a ValueError, but someone must have had a use case for getting an empty sequence. It seems to me that there is a more meaningful symantics. Simply put, a sequence multiplied by -1 can give a reversed sequence. There is alre

Re: sequence multiplied by -1

2010-09-25 Thread Mel
Stefan Schwarzer wrote: > On 2010-09-25 15:54, Yingjie Lan wrote: >> The first one is simpler (4 chars v.s. 9 chars). >> I thought it was also intuitive because if you multiply >> a vector by -1, you should get a vector >> in the reversed direction. But, intuitiveness depends >> on who you are, wh

Re: sequence multiplied by -1

2010-09-25 Thread Stefan Schwarzer
Hi, On 2010-09-25 15:54, Yingjie Lan wrote: > The first one is simpler (4 chars v.s. 9 chars). One thing is whether a certain form is shorter, another thing to take into account is how often you need the functionality. > I thought it was also intuitive because if you multiply > a vector by -1, y

Re: sequence multiplied by -1

2010-09-25 Thread Yingjie Lan
Hi, > > In my opinion this _isn't_ a situation where it's good. :) > >     L[::-1] > > is only marginally longer than > >     -1 * L > > I think this small gain doesn't justify "violating" this > "Python Zen" rule (from `import this`): > >     There should be one-- and preferably only one >

Re: sequence multiplied by -1

2010-09-25 Thread Stefan Schwarzer
Hi, On 2010-09-25 14:11, Yingjie Lan wrote: > Having more than one way of doing things sometimes is good. In my opinion this _isn't_ a situation where it's good. :) L[::-1] is only marginally longer than -1 * L I think this small gain doesn't justify "violating" this "Python Zen" rule

Re: sequence multiplied by -1

2010-09-25 Thread Yingjie Lan
len(l*n) == len(l) * abs(n), which is also broken under current python3k. if you think len(..) as a mathematical norm, the above invariance makes perfect sense: || a * b || == ||a|| * |b|, b is real > > > Simply put, a sequence multiplied by -1 can give a > reversed sequence. > >

Re: sequence multiplied by -1

2010-09-25 Thread Thomas Jollans
benefits for the operation to succeed for any integer operand. > > Simply put, a sequence multiplied by -1 can give a reversed sequence. For that, we have slicing. A negative step value produces a reverse slice of the list. You can't argue that this makes sense, can you &g

sequence multiplied by -1

2010-09-25 Thread Yingjie Lan
Hi, I noticed that in python3k, multiplying a sequence by a negative integer is the same as multiplying it by 0, and the result is an empty sequence. It seems to me that there is a more meaningful symantics. Simply put, a sequence multiplied by -1 can give a reversed sequence. Then for any