<br><br><div class="gmail_quote">On Thu, Feb 12, 2009 at 10:27 PM, Bruce Frederiksen <span dir="ltr"><<a href="mailto:dangyogi@gmail.com">dangyogi@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="Ih2E3d">Raymond Hettinger wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">I recommend dropping the notion of forwarding from the proposal.<br>
The idea is use-case challenged, complicated, and should not be<br>
hidden behind new syntax.<br>
<br>
Would hate for this to become a trojan horse proposal<br>
when most folks just want a fast iterator pass-through mechasism:<br>
</blockquote></div>
I don't really understand your objection.  How does adding the ability to forward send/throw values and closing the subgenerator in any way whatsoever get in the way of you using this as a fast iterator pass-through mechanism?<br>

<br>
I agree that 98% of the time the simple pass-through mechanism is all that will be required of this new feature.  And I agree that this alone is sufficient motivation to want to see this feature added.  But I have done quite a bit of work with nested generators and end up having to use itertools.chain, which also doesn't support the full generator behavior. <br>
<snip></blockquote><div><br>One of the advantages of full support of generators in a new 'yield from' is future proofing. Given the statement:<br><br><div style="margin-left: 40px;">The effect is to run the iterator to exhaustion,<br>

during which time it behaves as though it were communicating directly<br>
with the caller of the generator containing the ``yield from`` expression<br>
(the "delegating generator").<br></div><br>If, hypothetically, Python were to add some new feature to generators then those would automatically work in this context. Every place in current code which implements this kind of mechanism is not future proof. <br>
<br>I didn't follow all the variations on the for loop, but regarding send, it seems to me that a natural case is this:<br><br>    for x in foo:<br>        bar = process(x)<br>        foo.send(bar)<br><br>which sends the value bar to the generator and the value that comes back is used in the next iteration of the loop. I know that what I wrote doesn't do that so what I really mean is something like this but easier to write:<br>
<br>    try:<br>        x = foo.next()<br>        while True:<br>            bar = process(x)<br>            x = foo.send(bar)<br>    except StopIteration:<br>        pass<br><br>and the syntax that occurs to me is:<br><br>
    for x in foo:<br>
        bar = process(x)<br>
        continue bar<br><br>As to chaining generators, I don't see that as a for loop-specific feature. If that's useful in a for, then it's useful outside and should stand on its own. (And I withhold judgment on that as I don't yet see a benefit to the new syntax vs. what's available today.)<br>
</div></div>