
Greg Ewing <greg.ewing@...> writes:
Traversing it with a generator:
def traverse(node): if node: yield process_node(node) yield from traverse(node.left) yield from traverse(node.right)
Do you still think an unrolled version would be equally clear? If so, you have extremely different tastes from me!
Of course, I admit the "yield from" version is simpler :) However, if there isn't a specialized optimization in the interpreter, it will also probably be slower (because it switches between frames a lot, which is likely expensive, although I don't know of any timings). Besides, my point was to show that you didn't /need/ "yield from" to write a linear traversal generator, and the 15 or so lines of that generator are sufficiently generic to be reused from project to project. (my opinion on your PEP being that it brings the complication inside the interpreter itself, especially if you want to implement the feature in an optimized way. I haven't read the scheduler example yet, though...) Regards Antoine.