Bidirectional Generators

W

william tanksley

Okay, I'm almost finished with my first bidirectional generator. By
"almost finished" I mean both that it's almost working, and that I'm
almost about to replace it with a class that works a bit more like
what I currently understand.

Surely some other people have worked with this feature... Are there
any pages that discuss how it's been useful?

No, I don't want to see an implementation of coroutines. I get that
one already. :)

-Wm
 
P

Paddy

Okay, I'm almost finished with my first bidirectional generator. By
"almost finished" I mean both that it's almost working, and that I'm
almost about to replace it with a class that works a bit more like
what I currently understand.

Surely some other people have worked with this feature... Are there
any pages that discuss how it's been useful?

No, I don't want to see an implementation of coroutines. I get that
one already. :)

-Wm

What's one of them then?

- Paddy.
 
W

william tanksley

Paddy said:
What's one of them then?

I'm sorry, I don't know what you mean.

Meanwhile, more pertinently: I did get my generator working, and then
I replaced it with a class that did the same thing in less than a
quarter of the number of lines. So... I'm not going to worry about
that anymore. My use case obviously wasn't the right one for them.

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.

-Wm
 
J

Jeff

I'm sorry, I don't know what you mean.

Meanwhile, more pertinently: I did get my generator working, and then
I replaced it with a class that did the same thing in less than a
quarter of the number of lines. So... I'm not going to worry about
that anymore. My use case obviously wasn't the right one for them.

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.


-Wm

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).
 
W

william tanksley

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top