Author gvanrossum
Recipients
Date 2004-03-22.23:00:59
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
Logged In: YES 
user_id=6380

Sorry, I meant the first, not the last. I was confused about 
how the 'for' clauses are nested, but the outermost one is 
the first.

So the nesting remark is probably just confusing and wrong; 
ignore it.

What I meant is:

(f(x,y) for x in A() for y in B(x))

should IMO precompute A(), but not B(x). I guess the 
equivalent generator function would be:

def __gen(__outer__=A(), f=f, B=B):
  for x in __outer__:
    for y in B(x):
      yield f(x,y)

In general the value of every free variable used anywhere 
except in the outer expression should be captured; the 
*value* of the outer expression should be captured. This 
should give the least surprising semantics in a variaty of use 
cases.
History
Date User Action Args
2007-08-23 15:31:38adminlinkissue872326 messages
2007-08-23 15:31:38admincreate