Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re (tilly) 3: Perl 6 coroutines (RFC 31)

by tilly (Archbishop)
on Jul 13, 2001 at 20:58 UTC ( #96478=note: print w/replies, xml ) Need Help??

in reply to Re: Re (tilly) 1: Perl 6 coroutines (RFC 31)
in thread Perl 6 coroutines (RFC 31)

Personally I don't think that the issue of avoiding conflict is that bad. If you really want multiple instances of the same thing, then just have a function that returns a closure, and each closure maintains its own state.

Anyways the yield idea can work really nicely. As I said before, try Ruby. Ruby combines yield with a nice piece of syntactic sugar. In Ruby you can call functions 2 ways. In one way you just call the function. In the other you call the function and pass a block as an extra argument. When you do the latter then any yield will call the block. (You can also detect which way you are being called and function appropriately.)

So what you get is effectively the same as creating a closure in your context and passing it to the function, and having it call the closure. However it works really nicely because, even though that is what you are doing, there is a lot less machinery needed to set it up. And it seems that people who have a hard time getting their heads around the idea, You encapsulate a closure and then pass it in have no problem with the idea of passing a block to a method named each and having your block called on each thing encapsulated in your object.

As Larry Wall has noted, sometimes sugar is worth it in its own right. Even if you cannot readily use yield for the full generality of what you want, it can work really nicely.

As I said before, you can play around with Ruby now to get a sense of what this feature will be like in Perl 6. (Of course many of the other features of Perl 6 are missing in Ruby...)

  • Comment on Re (tilly) 3: Perl 6 coroutines (RFC 31)

Replies are listed 'Best First'.
Re: Re (tilly) 3: Perl 6 coroutines (RFC 31)
by John M. Dlugosz (Monsignor) on Jul 13, 2001 at 22:24 UTC
    Yes, I looked at Ruby when it was mentioned last month. I looked at the block thing compared with Perl.

    If Perl allows the implicit sub at any position rather than only the first, we can do the same thing like Ruby. Having yield will make some things easier, like the tree traversal.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://96478]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2020-10-29 22:12 GMT
Find Nodes?
    Voting Booth?
    My favourite web site is:

    Results (274 votes). Check out past polls.