Bidirectional Generators

william tanksley wtanksleyjr at gmail.com
Mon Aug 4 14:16:25 EDT 2008


Jeff <jeffo... at gmail.com> wrote:
> william tanksley <wtanksle... at gmail.com> wrote:
> > I'm still curious, though, whether anyone's written any code that
> > actually uses yield _and_ send() to do anything that isn't in the
> > original PEP.

> I have.  An iterator that could backtrack itself without the user
> having to remember previous states.  It would just send back something
> like reader.send('prev_token') or reader.send(-1).

Ah, nice! I now remember briefly thinking that such a thing should be
possible. Interestingly, I just recently wrote a backtracking search,
so I could have used such a thing -- it's a pity that I didn't
remember about send() while I was doing that.

I may have to alter my design to see what happens.

-Wm



More information about the Python-list mailing list