Re: Generator expressions vs. comprehensions

2010-05-25 Thread Terry Reedy
On 5/25/2010 1:09 PM, Terry Reedy wrote: On 5/25/2010 3:08 AM, Peter Otten wrote: Michele Simionato wrote: I think not turning the list-comp into syntactic sugar for list(genexp) in py3 is a missed opportunity. Implementing it that way was tried but was much slower than the current implemen

Re: Generator expressions vs. comprehensions

2010-05-25 Thread Terry Reedy
On 5/25/2010 3:08 AM, Peter Otten wrote: Michele Simionato wrote: I think not turning the list-comp into syntactic sugar for list(genexp) in py3 is a missed opportunity. Implementing it that way was tried but was much slower than the current implementation. If one uses StopIteration as it i

Re: Generator expressions vs. comprehensions

2010-05-25 Thread Michele Simionato
On May 25, 9:08 am, Peter Otten <__pete...@web.de> wrote: > But the list comprehension is already non-equivalent to the for loop as the > loop variable isn't leaked anymore. We do have three similar constructs with > subtle differences. > > I think not turning the list-comp into syntactic sugar for

Re: Generator expressions vs. comprehensions

2010-05-25 Thread Peter Otten
Michele Simionato wrote: > On May 25, 12:47 am, Carl Banks wrote: >> The situation here is known. It can't be corrected, even in Python 3, >> without modifying iterator protocol to tie StopIteration to a specific >> iterator. This is possible and might be worth it to avoid hard-to- >> diagnose

Re: Generator expressions vs. comprehensions

2010-05-24 Thread Michele Simionato
On May 25, 12:47 am, Carl Banks wrote: > The situation here is known.  It can't be corrected, even in Python 3, > without modifying iterator protocol to tie StopIteration to a specific > iterator.  This is possible and might be worth it to avoid hard-to- > diagnose bugs but it would complicate ite

Re: Generator expressions vs. comprehensions

2010-05-24 Thread Antoine Pitrou
On Mon, 24 May 2010 15:47:32 -0700 (PDT) Carl Banks wrote: > > > > Is this distinction generally known? Yes, it is. > > The generator expression > > behavior is understandable since a generator would do the same thing, > > but I'm disappointed that the inconsistency exists and wasn't fixed in >

Re: Generator expressions vs. comprehensions

2010-05-24 Thread Carl Banks
On May 24, 3:31 pm, Ian Kelly wrote: > Hi all, > > I just ran into an interesting but rather subtle little wart today. > The following expressions are not functionally equivalent, even in > Python 3: > > tuple(iterator.next() for i in xrange(n)) > > tuple([iterator.next() for i in xrange(n)]) > >

Generator expressions vs. comprehensions

2010-05-24 Thread Ian Kelly
Hi all, I just ran into an interesting but rather subtle little wart today. The following expressions are not functionally equivalent, even in Python 3: tuple(iterator.next() for i in xrange(n)) tuple([iterator.next() for i in xrange(n)]) In the first case, if iterator.next() raises a StopItera