yield_all needed in Python
Terry Reedy
tjreedy at udel.edu
Mon Feb 28 20:54:39 EST 2005
"Douglas Alan" <nessus at mit.edu> wrote in message
news:lck6osnu68.fsf at gaffa.mit.edu...
> We can shorten the code--and make it run in O(N) time--by adding a
> new
> keyword to replace the "for v in ...: yield v" pattern:
Maybe. Until you define the semantics of yield_all and at least outline an
implementation, I am not convinced of 'run in o(n) time'. There was once a
several-post discussion of a related idea of having yield somehow,
magically, skip intermediate generators that only yielded value on up,
without tranformation. But it was never clear how to do this practically
without negatively impacting all generators. Cetainly, if <yield_all
iterator> == <for i in iterator: yield i>, I don't see how anything is
gained except for a few keystrokes. If <yield_all iterator> == <yield
list(i for i in iterator)> then the replacement is a semantic change.
> def in_order(self):
> if self.left is not None:
> yield_all self.left.in_order():
> yield self.value
> if self.right is not None:
> yield_all self.right.in_order():
If and when I write a text-based double-recursion to iteration transformer,
a pseudokeyword might be be an idea for indicating that stacked yields are
identify functions and therefore bypassable.
Terry J. Reedy
More information about the Python-list
mailing list