
I'm the originator of the patch (SF patch 872326 - generator expression). If "immediate evaluation of expr in generator expression" means that generator expression: (x for x in range()) should be equivalent to: def __foo(_range=range()): for x in _range: yield x it seems to me that generator expression has almost no merit over list comprehension. I think the merit of generator is that it does not need to allocate all the memory that it needs in the initial time, right? Or, am I confusing something? :) Regards, Jiwon. ----- Original Message ----- From: "Michael Hudson" <mwh@python.net> To: <python-dev@python.org> Sent: Tuesday, January 13, 2004 12:55 AM Subject: Re: [Python-Dev] [872326] generator expression implementation
Jeremy Hylton <jeremy@alum.mit.edu> writes:
On Mon, 2004-01-12 at 05:58, Armin Rigo wrote:
Sorry to bring this out again, I didn't find a reference about the following issue in generator expressions:
(for x in expr)
When should 'expr' be evaluated? A priori, one would expect it to be evaluated immediately, but it is not what the suggested implementation does:
def __gen(): for x in expr: yield x __gen()
First a quick clarification: Is the "suggested implementation" SF patch 872326 or is it that implementation sketch in PEP 289? The latter certainly suggests it, but it's hard to tell even then if it's intentional. Perhaps we should work out the formal specification part of the PEP in parallel with the implementation. The PEP currently says that the reference manual should contain a specification, but that spec is supposed to be part of the PEP, too.
I agree, at any rate, that the expression should be evaluated immediately. That's easy enough to implement:
def __gen(it): for x in it: yield x __gen()
Should be __gen(expr), right?
Cheers, mwh
-- For their next act, they'll no doubt be buying a firewall running under NT, which makes about as much sense as building a prison out of meringue. -- -:Tanuki:- -- http://home.xnet.com/~raven/Sysadmin/ASR.Quotes.html