Joshua Gatcomb wrote:
> On 5/4/05, Luke Palmer <[EMAIL PROTECTED]> wrote:
>> On 5/4/05, Joshua Gatcomb <[EMAIL PROTECTED]> wrote:
>> > So without asking for S17 in its entirety to be written, is it
>> > possible to get a synopsis of how p6 will do coroutines?  I ask
>> > because after reading Dan's "What the heck is:  a coroutine", it is
>> > clear there is more than one way to dictate behavior.
>> Well, one way is to use generating functions:
>>     my @a = gather {
>>         for 1..10 {
>>             say;
>>             take;
>>         }
>>     }
> Ok - this isn't what I was expecting at all.  That doesn't make it a
> bad thing.  Given something that looks a lot more like a typical
> coroutine:

  sub example(...) {
    my $index = 0;
    my @a    := gather {
      ...coroutine code here, use "take" to yield a result...;

    return { @a[$index++] };

  my $gen = example(...);
  say $gen();
  say $gen();
  say $gen();

(FWIW, I like something along the lines of "is coroutine" and then
"yield" to yield a result, too, but I don't have a strong opinion on


Linux, the choice of a GNU | Row, row, row your bits, gently down the
generation on a dual AMD   | stream...  
Athlon!                    | 

Reply via email to