
Armin Rigo wrote:
Hello,
On Fri, Oct 17, 2003 at 11:55:53AM -0600, Shane Holloway (IEEE) wrote:
mygenerator = x for x in S
for y in x for x in S: print y
return x for x in S
Interesting but potentially confusing: we could expect the last one to mean that we executing 'return' repeatedly, i.e. returning a value more than once, which is not what occurs. Similarily,
yield x for x in g()
in a generator would be quite close to the syntax discussed some time ago to yield all the values yielded by a sub-generator g, but in your proposal it wouldn't have that meaning: it would only yield a single object, which happens to be an iterator with the same elements as g().
Yes, this is one of the things I trying to getting at -- If gencomps are expressions, then they must be expressions everywhere, or my poor brain will explode. As for the subgenerator "unrolling", I think there has to be something added to the yield statement to accomplish it -- because it is also useful to yield a generator itself and not have it unrolled. My favorite was "yield *S" for that discussion...\ -Shane Holloway