Re: [Python-3000] Using *a for packing in lists and other places

2008-03-19 Thread Charles Merriam
On Mon, Mar 17, 2008 at 3:37 PM, Terry Reedy <[EMAIL PROTECTED]> wrote: > ... > Can you give another rule that you prefer and that I can comprehend and > that I can explain to Python newcomers? The OP only gave a few examples of > * usage and (initially) no rule that I saw. Really, it is as c

Re: [Python-3000] Using *a for packing in lists and other places

2008-03-17 Thread Terry Reedy
"Marcin 'Qrczak' Kowalczyk" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] | Dnia 16-03-2008, N o godzinie 18:20 -0400, Terry Reedy pisze: | | > The rule I suggested is 'execute the statement the same *as if* the | > iterable items had been written in the code as a comma sequence'.

Re: [Python-3000] Using *a for packing in lists and other places

2008-03-17 Thread Marcin ‘Qrczak’ Kowalczyk
Dnia 16-03-2008, N o godzinie 18:20 -0400, Terry Reedy pisze: > The rule I suggested is 'execute the statement the same *as if* the > iterable items had been written in the code as a comma sequence'. One reason I don't like this rule is that it works on the level of the token sequence rather th

Re: [Python-3000] Using *a for packing in lists and other places

2008-03-16 Thread Greg Ewing
Terry Reedy wrote: > The fact that the '*' would be redundant in some contexts and therefore > useless should not necessarily make it syntax error in that context. It does allow a lone *exp to be given a special meaning in some contexts, such as yield *exp. Although I'm still not sure that's a go

Re: [Python-3000] Using *a for packing in lists and other places

2008-03-16 Thread Thomas Wouters
On Sun, Mar 16, 2008 at 4:33 PM, Greg Ewing <[EMAIL PROTECTED]> wrote: > Thomas Wouters wrote: > > > > [Guido] asked for 'f(*a, b, c)' to be valid, but it only makes sense > > to allow, say, 'f(*a, b, *c)' too, and he hasn't said 'no' to that. > > And then, of course, people are going to want > to

Re: [Python-3000] Using *a for packing in lists and other places

2008-03-16 Thread Phillip J. Eby
At 02:49 PM 3/16/2008 -0500, Guido van Rossum wrote: >On Sun, Mar 16, 2008 at 1:31 PM, Phillip J. Eby <[EMAIL PROTECTED]> wrote: > > Btw, would you mind pronouncing (or at least commenting) on PEP 365, > > so that I can proceed with the work -- or not. > >Can you point me to past discussions? IST

Re: [Python-3000] Using *a for packing in lists and other places

2008-03-16 Thread Greg Ewing
Thomas Wouters wrote: > > [Guido] asked for 'f(*a, b, c)' to be valid, but it only makes sense > to allow, say, 'f(*a, b, *c)' too, and he hasn't said 'no' to that. And then, of course, people are going to want to have multiple ** arguments, too... -- Greg _

Re: [Python-3000] Using *a for packing in lists and other places

2008-03-16 Thread Terry Reedy
"Thomas Wouters" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] | On Sat, Mar 15, 2008 at 2:58 PM, Terry Reedy <[EMAIL PROTECTED]> wrote: | | > | > | Also, yielding everything from an iterator: | > | | > | >>> def flatten(iterables): | > | ... for it in iterables: | > | ...

Re: [Python-3000] Using *a for packing in lists and other places

2008-03-16 Thread Guido van Rossum
On Sun, Mar 16, 2008 at 1:31 PM, Phillip J. Eby <[EMAIL PROTECTED]> wrote: > Btw, would you mind pronouncing (or at least commenting) on PEP 365, > so that I can proceed with the work -- or not. Can you point me to past discussions? ISTR that this is controversial. -- --Guido van Rossum (home

Re: [Python-3000] Using *a for packing in lists and other places

2008-03-16 Thread Phillip J. Eby
At 12:55 PM 3/16/2008 -0500, Guido van Rossum wrote: >On Sun, Mar 16, 2008 at 12:48 PM, Phillip J. Eby ><[EMAIL PROTECTED]> wrote: > > At 10:00 AM 3/16/2008 -0500, Guido van Rossum wrote: > > >(a) *if* we're going to do this, it should also be done for function > > >calls (though not for functio

Re: [Python-3000] Using *a for packing in lists and other places

2008-03-16 Thread Guido van Rossum
On Sun, Mar 16, 2008 at 12:48 PM, Phillip J. Eby <[EMAIL PROTECTED]> wrote: > At 10:00 AM 3/16/2008 -0500, Guido van Rossum wrote: > >(a) *if* we're going to do this, it should also be done for function > >calls (though not for function defs). I'd like all of these to be > >legal (and their inte

Re: [Python-3000] Using *a for packing in lists and other places

2008-03-16 Thread Phillip J. Eby
At 10:00 AM 3/16/2008 -0500, Guido van Rossum wrote: >(a) *if* we're going to do this, it should also be done for function >calls (though not for function defs). I'd like all of these to be >legal (and their interpretation is obvious): > > f(a, b, *x, k=val) > f(a, *x, b, k=val) > f(*x, a, b,

Re: [Python-3000] Using *a for packing in lists and other places

2008-03-16 Thread Guido van Rossum
On Sat, Mar 15, 2008 at 6:01 PM, Thomas Wouters <[EMAIL PROTECTED]> wrote: > On Sat, Mar 15, 2008 at 3:21 PM, Guido van Rossum <[EMAIL PROTECTED]> wrote: > > This post does point out an inconistency in Thomas's patch: > > > > def f(): > > yield 1, 2, 3 > > > > Yields a single three-tuple. > > > >

Re: [Python-3000] Using *a for packing in lists and other places

2008-03-16 Thread Thomas Wouters
On Sat, Mar 15, 2008 at 9:51 PM, Neil Toronto <[EMAIL PROTECTED]> wrote: > Thomas Wouters wrote: > > > > On Sat, Mar 15, 2008 at 2:58 PM, Terry Reedy <[EMAIL PROTECTED] > > > wrote: > > > > | Also, yielding everything from an iterator: > > | > > | >>> def flat

Re: [Python-3000] Using *a for packing in lists and other places

2008-03-16 Thread Thomas Wouters
On Sat, Mar 15, 2008 at 11:26 PM, Greg Ewing <[EMAIL PROTECTED]> wrote: > Thomas Wouters wrote: > > > > On Sat, Mar 15, 2008 at 6:07 PM, Greg Ewing <[EMAIL PROTECTED] > > > wrote: > > > > *a, b, c = a, b, *c > > > > +0 on allowing * in other than the last pos

Re: [Python-3000] Using *a for packing in lists and other places

2008-03-16 Thread Thomas Wouters
On Sat, Mar 15, 2008 at 6:07 PM, Greg Ewing <[EMAIL PROTECTED]> wrote: > Thomas Wouters wrote: > > >>> a, b = *c > > File "", line 1 > > SyntaxError: can use starred expression only as assignment target > > That error message isn't really accurate, since in > > > >>> a, b = (*c,) > the *c is

Re: [Python-3000] Using *a for packing in lists and other places

2008-03-16 Thread Georg Brandl
Neil Toronto schrieb: > Besides, as the SmugLispWeenies have noted, Python is becoming more like > Lisp all the time: > > (setq obj '(an ex-parrot)) ; (AN EX-PARROT) > `(I have ,obj) ; (I HAVE (AN EX-PARROT)) > `(I have ,@obj) ; (I HAVE AN EX-PARROT) Onl

Re: [Python-3000] Using *a for packing in lists and other places

2008-03-15 Thread Arnaud Delobelle
On 15 Mar 2008, at 16:15, Guido van Rossum wrote: > Thomas Wouters suggests some new syntax: > > http://bugs.python.org/issue2292 > a, b, *c = range(5) > *a, b, c = a, b, *c a, b, c > ([0, 1, 2], 3, 4) [ *a, b, c ] > [0, 1, 2, 3, 4] L = [ a, (3, 4), {5}, {6: None}, (i for

Re: [Python-3000] Using *a for packing in lists and other places

2008-03-15 Thread Greg Ewing
Thomas Wouters wrote: > > On Sat, Mar 15, 2008 at 6:07 PM, Greg Ewing <[EMAIL PROTECTED] > > wrote: > > *a, b, c = a, b, *c > > +0 on allowing * in other than the last position. > > The left-hand side of all this is already in. Only the rhs is new. I'm w

Re: [Python-3000] Using *a for packing in lists and other places

2008-03-15 Thread Greg Ewing
Charles Merriam wrote: > -1. > > While the syntax has a basic beauty, it requires too much odd explanation. On further reflection, I think I would only be in favour of 'yield *it' if it permitted an optimisation allowing it to run more efficently than an explicit for-loop. In the absence of any

Re: [Python-3000] Using *a for packing in lists and other places

2008-03-15 Thread Neil Toronto
Thomas Wouters wrote: > > On Sat, Mar 15, 2008 at 2:58 PM, Terry Reedy <[EMAIL PROTECTED] > > wrote: > > | Also, yielding everything from an iterator: > | > | >>> def flatten(iterables): > | ... for it in iterables: > | ... yield *it > >

Re: [Python-3000] Using *a for packing in lists and other places

2008-03-15 Thread Greg Ewing
Thomas Wouters wrote: > >>> a, b = *c > File "", line 1 > SyntaxError: can use starred expression only as assignment target That error message isn't really accurate, since in > >>> a, b = (*c,) the *c is not an assignment target. Also, the message implies that *c = a, b should be valid

Re: [Python-3000] Using *a for packing in lists and other places

2008-03-15 Thread Talin
Guido van Rossum wrote: > Also, yielding everything from an iterator: > def flatten(iterables): > ... for it in iterables: > ... yield *it > ... L = [ a, (3, 4), {5}, {6: None}, (i for i in range(7, 10)) ] flatten(L) > [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] > > What do people

Re: [Python-3000] Using *a for packing in lists and other places

2008-03-15 Thread Thomas Wouters
On Sat, Mar 15, 2008 at 6:07 PM, Greg Ewing <[EMAIL PROTECTED]> wrote: > Guido van Rossum wrote: > > Thomas Wouters suggests some new syntax: > > a, b, *c = range(5) > > +1 on this. > > *a, b, c = a, b, *c > > +0 on allowing * in other than the last position. > The left-hand side of all t

Re: [Python-3000] Using *a for packing in lists and other places

2008-03-15 Thread Greg Ewing
Guido van Rossum wrote: > Thomas Wouters suggests some new syntax: a, b, *c = range(5) +1 on this. *a, b, c = a, b, *c +0 on allowing * in other than the last position. > ... for it in iterables: > ... yield *it +0.5 (due to consistency problems pointed out in others' comm

Re: [Python-3000] Using *a for packing in lists and other places

2008-03-15 Thread Greg Ewing
Thomas Wouters wrote: > > I do not think > collecting a (potentially ever-growing) list of results is really the > right thing to do, do you? For those cases where it is, perhaps one should be able to write [yield *it] and have it treated as a kind of list comprehension. -- Greg

Re: [Python-3000] Using *a for packing in lists and other places

2008-03-15 Thread Charles Merriam
-1. While the syntax has a basic beauty, it requires too much odd explanation. "*" and "**" are already binary operators. The '*' unary operator can confuse migrating programmers already. It makes puzzles too easy, e.g., yield **[2**3*i, for i in range(2*3**4)] On Sat, Mar 15, 2008 at 6:55 PM

Re: [Python-3000] Using *a for packing in lists and other places

2008-03-15 Thread Phillip J. Eby
At 06:33 PM 3/15/2008 -0500, Michael Urman wrote: > > > I'm not sure how to solve this except by adopting a different syntax > > > for the multiple-yield. Perhaps > > > > > > *yield x > > > > If there really were an inconsistency here, I would certainly not suggest > > fixing it that way, yuuueghh.

Re: [Python-3000] Using *a for packing in lists and other places

2008-03-15 Thread Michael Urman
> > I'm not sure how to solve this except by adopting a different syntax > > for the multiple-yield. Perhaps > > > > *yield x > > If there really were an inconsistency here, I would certainly not suggest > fixing it that way, yuuueghh. Agreed about *yield looking yucky. In a previous thread somewh

Re: [Python-3000] Using *a for packing in lists and other places

2008-03-15 Thread Thomas Wouters
On Sat, Mar 15, 2008 at 3:21 PM, Guido van Rossum <[EMAIL PROTECTED]> wrote: > This post does point out an inconistency in Thomas's patch: > > def f(): > yield 1, 2, 3 > > Yields a single three-tuple. > > But > > def f(): > yield *[1, 2], 3 > > Yields three separate values. Uhm, what? It doesn

Re: [Python-3000] Using *a for packing in lists and other places

2008-03-15 Thread Guido van Rossum
This post does point out an inconistency in Thomas's patch: def f(): yield 1, 2, 3 Yields a single three-tuple. But def f(): yield *[1, 2], 3 Yields three separate values. I think this is inconsistent, since (1, 2, 3) and (*[1, 2], 3) are equivalent, and so are yield 1, 2, 3 and yi

Re: [Python-3000] Using *a for packing in lists and other places

2008-03-15 Thread Thomas Wouters
On Sat, Mar 15, 2008 at 2:58 PM, Terry Reedy <[EMAIL PROTECTED]> wrote: > > | Also, yielding everything from an iterator: > | > | >>> def flatten(iterables): > | ... for it in iterables: > | ... yield *it > > Following the general rule above for *exp, that would be the same as yield >

Re: [Python-3000] Using *a for packing in lists and other places

2008-03-15 Thread Terry Reedy
"Guido van Rossum" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] | Thomas Wouters suggests some new syntax: I see this as two suggestions: 1. Complete the extension of the validity of *expression syntax from function call/definition to expression/assignment. 2. Give *expression a

Re: [Python-3000] Using *a for packing in lists and other places

2008-03-15 Thread Thomas Wouters
On Sat, Mar 15, 2008 at 2:05 PM, BJörn Lindqvist <[EMAIL PROTECTED]> wrote: > On Sat, Mar 15, 2008 at 4:15 PM, Guido van Rossum <[EMAIL PROTECTED]> > wrote: > > >>> L = [ a, (3, 4), {5}, {6: None}, (i for i in range(7, 10)) ] > > >>> [ *item for item in L ] > > [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >

Re: [Python-3000] Using *a for packing in lists and other places

2008-03-15 Thread BJörn Lindqvist
On Sat, Mar 15, 2008 at 4:15 PM, Guido van Rossum <[EMAIL PROTECTED]> wrote: > >>> L = [ a, (3, 4), {5}, {6: None}, (i for i in range(7, 10)) ] > >>> [ *item for item in L ] > [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] Can you mix freely? >>> [*(*item, *item) for item in L] [0, 1, 2, 0, 1, 2, 3, 4, 3, 4,

Re: [Python-3000] Using *a for packing in lists and other places

2008-03-15 Thread Thomas Wouters
On Sat, Mar 15, 2008 at 12:44 PM, Neville Grech Neville Grech < [EMAIL PROTECTED]> wrote: > What about co-routines? > They're out of luck. Your code below doesn't work (the 'yield *it' syntax always results in None; any sends are discarded.) I do not think collecting a (potentially ever-growing)

Re: [Python-3000] Using *a for packing in lists and other places

2008-03-15 Thread Georg Brandl
Guido van Rossum schrieb: > Thomas Wouters suggests some new syntax: > > http://bugs.python.org/issue2292 > a, b, *c = range(5) > *a, b, c = a, b, *c a, b, c > ([0, 1, 2], 3, 4) [ *a, b, c ] > [0, 1, 2, 3, 4] L = [ a, (3, 4), {5}, {6: None}, (i for i in range(7, 10)) ] >

Re: [Python-3000] Using *a for packing in lists and other places

2008-03-15 Thread Neville Grech Neville Grech
What about co-routines? >>> def coroutine(): ... a, b = (yield *[1,2]) ...print (a) ...print (b) ... >>> cr=coroutine() >>> next(cr) 1 >>> cr.send(3) 2 >>> cr.send(4) 3 4 >>> On Sat, Mar 15, 2008 at 7:21 PM, Nick Coghlan <[EMAIL PROTECTED]> wrote: > Guido van Rossum wrote: > > What

Re: [Python-3000] Using *a for packing in lists and other places

2008-03-15 Thread Nick Coghlan
Guido van Rossum wrote: > What do people think? I think this idea (or variants thereof) has been suggested a few times over the years, and I don't think the arguments against it have ever been particularly compelling. The difference this time is that PEP 3132 has done the work of thrashing out

Re: [Python-3000] Using *a for packing in lists and other places

2008-03-15 Thread Paul Moore
On 15/03/2008, Guido van Rossum <[EMAIL PROTECTED]> wrote: > Thomas Wouters suggests some new syntax: > > http://bugs.python.org/issue2292 [...] > What do people think? I like it. It's on the border of being too obscure (the examples are logical, but I need to think to apply the logic - if you s

Re: [Python-3000] Using *a for packing in lists and other places

2008-03-15 Thread Brett Cannon
On Sat, Mar 15, 2008 at 11:15 AM, Guido van Rossum <[EMAIL PROTECTED]> wrote: > Thomas Wouters suggests some new syntax: > > http://bugs.python.org/issue2292 > > >>> a, b, *c = range(5) > > >>> *a, b, c = a, b, *c > >>> a, b, c > ([0, 1, 2], 3, 4) > >>> [ *a, b, c ] > [0, 1, 2, 3, 4] > >>>

Re: [Python-3000] Using *a for packing in lists and other places

2008-03-15 Thread Thomas Wouters
On Sat, Mar 15, 2008 at 9:15 AM, Guido van Rossum <[EMAIL PROTECTED]> wrote: > Thomas Wouters suggests some new syntax: > > http://bugs.python.org/issue2292 > > >>> a, b, *c = range(5) > > >>> *a, b, c = a, b, *c > >>> a, b, c > ([0, 1, 2], 3, 4) > >>> [ *a, b, c ] > [0, 1, 2, 3, 4] > >>> L = [ a,