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

2008-03-15 Thread Guido van Rossum
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)) ] >>> [ *item for item in L ] [0, 1, 2, 3, 4, 5,

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,

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 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 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 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 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 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 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 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 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: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 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 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 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 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.

[Python-3000] svnmerge - three broken tests

2008-03-15 Thread Christian Heimes
Hi guys! I hope you all have fun at PyCon! I hope I'll be able to attend to PyCon next year. I've spent the better part of the evening to merge changes from the trunk into py3k for the sprint. I got all tests except of three to pass: test_datetime test_struct test_tokenize Have fun! Christi

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 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 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 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 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] svnmerge - three broken tests

2008-03-15 Thread skip
Christian> I've spent the better part of the evening to merge changes Christian> from the trunk into py3k for the sprint. I got all tests Christian> except of three to pass: Christian>test_datetime test_struct test_tokenize Christian, I checked in a change to datetime today.

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] svnmerge - three broken tests

2008-03-15 Thread Mark Dickinson
On Sat, Mar 15, 2008 at 8:00 PM, Christian Heimes <[EMAIL PROTECTED]> wrote: > > test_datetime test_struct test_tokenize > I think I've fixed test_datetime and test_struct. I'm less sure what to do for test_tokenize; the main cause of failure seems to be doctests containing syntax that was va

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] svnmerge - three broken tests

2008-03-15 Thread Mark Dickinson
I think test_tokenize is now fixed, too. Mark ___ Python-3000 mailing list [email protected] http://mail.python.org/mailman/listinfo/python-3000 Unsubscribe: http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com

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

[Python-3000] Optimising nested generators

2008-03-15 Thread Greg Ewing
Talin wrote: > > if a generator is yielding the > entire output of another generator, it might be possible to 'cut out the > middleman' and have the ultimate consumer of the values read the > innermost generator directly. On the face of things, it certainly seems as though such a thing *ought*

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 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