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;
>         }
>     }
>
> (Where that = might be spelled :=).  Here, the code is not executed
> until an element of @a is demanded.  It is executed as many times as
> necessary to fetch that element, and then stopped in its tracks.

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 is coroutine {
   yield 1;
   yield 2;
   yield 3;
}

I would expect
for 1 .. 5 { say example() } to print "1\n2\n3\n1\n\2"

If I got fancy and added a parameter

sub example ( $num ) is coroutine {
   yield $num;
   yield $num + 1;
   yield $num - 2;
}

I would expect
for 1 .. 5 { say example( 7 ) } to print "7\n8\n6\n7\n8";

The questions I am really asking is:
1.  Will coroutines be supported at all?
2.  If yes, will they look like coroutines in other languages?
3.  If yes, in what ways will they be behave (handling of parameters
for instance)?
4.  Finally, what is the proper syntax for declaring and calling coroutines?

I am fine with a "we haven't got that far yet" answer.  I was just
hoping to write some tests to drive features.

>
> Luke
- Hide quoted text -
>
Cheers,
Joshua Gatcomb
a.k.a. L~R

Reply via email to