[Python-ideas] A Continuations Compromise in Python
Carl Johnson
cmjohnson.mailinglist at gmail.com
Sun May 3 08:44:27 CEST 2009
I have a question about the implementation of "yield from." I recall
hearing some talk about optimizing the stack in "yield from," but I
didn't catch all of the details. I take it that there will be some
steps taken to ensure that yield from's yield from their inner most
yielder without having to touch base at all the objects in between
whoever is asking for the value and whoever is giving it. That being
the case, will this example implementation of a linked list still blow
the stack for lists bigger than 1,000 items or not?
class LinkedList:
def __iter__(self):
yield self.value
if self.link: yield from self.link
If it does still blow up the stack, then it's no big deal, but if this
won't blow the stack up anymore, then it seems like there's very
little difference between the kind of recursive programming invited by
"yield from" and the kind of recursive programming invited by
"continue object". If you hate reading TCO code (and I take this to be
the #1 objection to adding TCO to Python, though there are also more
technical reasons), you're still going to get it, only using "yield
from" instead of "continue". So in that case, "continue" and "yield
from" should be thought of as a pair of stack optimizers, one for
functions and one for generators.
-- Carl
More information about the Python-ideas
mailing list