Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Experimental Coroutine support landed.
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  1 message - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Autrijus Tang  
View profile  
 More options May 20 2005, 11:42 am
Newsgroups: perl.perl6.compiler
From: autri...@autrijus.org (Autrijus Tang)
Date: Fri, 20 May 2005 23:42:53 +0800
Local: Fri, May 20 2005 11:42 am
Subject: Experimental Coroutine support landed.

A highly experimental implementation of coroutines has landed to Pugs.

The `coro` keyword denotes a coroutine.  It may appear at any place
where `sub` may appear, i.e. in both named and anonymous forms.

I borrowed the semantics from Coro::Cont on CPAN, with the following
restriction that you cannot return() from a coroutine, or yield()
from a non-coroutine.

Tests for coro should go to t/unspecced/, as one of the "speculative"
features.  Use it like this:

    coro flip_flop { yield 1; yield 0 }
    print flip_flop() while 1; # 1010101010....

As you can see, there is an implicit loop around coro's body.
state() and my() variables work as you would expect -- the former
stays in place, while the latter are regenerated when control falls
out from the block and reenters from the top.

Here is another example, courtesy of integral:

    my @generators = map -> $N { coro { yield $_ for 0..$N } } 0..9;
    say "{ map { $_() }, @generators }" for 0..9;

The above prints:

    0 0 0 0 0 0 0 0 0 0
    0 1 1 1 1 1 1 1 1 1
    0 0 2 2 2 2 2 2 2 2
    0 1 0 3 3 3 3 3 3 3
    0 0 1 0 4 4 4 4 4 4
    0 1 2 1 0 5 5 5 5 5
    0 0 0 2 1 0 6 6 6 6
    0 1 1 3 2 1 0 7 7 7
    0 0 2 0 3 2 1 0 8 8
    0 1 0 1 4 3 2 1 0 9

Please direct syntax-related questions and suggestions to p6l as separate
threads; I'd be happy to change the implementation in other ways as
specified by @Larry.

Thanks,
/Autrijus/

  application_pgp-signature_part
< 1K Download

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »