Talin wrote:
> 
> if a generator is yielding the 
> entire output of another generator, it might be possible to 'cut out the 
> middleman' and have the ultimate consumer of the values read the 
> innermost generator directly.

On the face of things, it certainly seems as though such a thing
*ought* to be possible. It would require keeping a stack of
generators somewhere, although I'm not sure exactly where.

Perhaps each generator frame could have a "referral" slot
which can contain a reference to another iterator. When a
generator hits a "yield *" statement, it puts the argument
into its referral slot.

Then, the next() method of a generator would first run
down the chain of referral slots until it gets to the
end (either a generator with nothing in its referral slot,
or a non-generator iterator), and resume the iterator found
there. If it's found to be exhausted, you would back up to
the previous one and resume that, etc., until you either
get a value or the outermost generator is exhausted.

Does that sound like it would be workable?

-- 
Greg
_______________________________________________
Python-3000 mailing list
Python-3000@python.org
http://mail.python.org/mailman/listinfo/python-3000
Unsubscribe: 
http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com

Reply via email to