http://qs1969.pair.com?node_id=351371


in reply to Coroutines in Perl

Interestingly, perl6 allows for coroutines. Parrot will be largely based on a closely related concept, called continuations.

(As far as I can tell, a continuation is a coroutine with it's state wrapped in an object.)

They're extremely useful in certian cases.

Think of a CGI script. If you have continuations, you can pretend that the entire conversation with the user takes place within one coherent program, and that you're waiting for the user to respond, instead of being re-invoked on every return.

Think of an iterator, that was written in terms of continuing it's running, instead of calling into the same sub over and over.

It's possible to write both things without using contations, but contuations can produce cleaner code... if used carefuly, and in the right places. (Much like threads, which are also related. Like threads, they can be tricky to get working properly, and they can produce ugly and innefficent code if used poorly.)