question about generators
Andreas.Leitgeb at siemens.at
Tue Aug 20 10:35:30 CEST 2002
Greg Ewing <see_reply_address at something.invalid> wrote:
> I've thought about this a bit more, and I think it can be done
> a lot more simply than that. All that's needed is a pointer in
> each generator-iterator that points to the subject of the
> current yield-every statement being executed, if any.
Maybe I'm misunderstanding this, but
I strongly want to oppose any implicit propagation of nested
generator-calls, whether recursive or not.
Even a recursive generator may choose to do whatever it likes
with the iterator returned from a sub-generator - even yield
it "as is"!
The previously suggested new pseudo-keyword "every" as in
yield every <iterator>
would be very clear, concise and good syntactic sugar for the current
for i in <iterator>: yield i
with some bonuses:
+ no local variable needs to be bound
+ speed (at least because of previous point :-)
+ could be used right of a colon:
if <whatever>: yield every <iterator>
The only "disadvantage" being, that it's a change in syntax
with some (likely marginal) effect in python's code-size.
There may be better words than "every", perhaps "each" sounds better
in this context.
Newsflash: Sproingy made it to the ground !
read more ... <http://avl.enemy.org/sproingy/>
More information about the Python-list