Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
Just another Perl shrine
 
PerlMonks  

Re: RFC: Simulating Ruby's "yield" and "blocks" in Perl

by sundialsvc4 (Monsignor)
on Apr 23, 2013 at 11:52 UTC ( #1030114=note: print w/ replies, xml ) Need Help??


in reply to RFC: Simulating Ruby's "yield" and "blocks" in Perl

I find co-routines useful, especially as filters or as generators for use in a loop.   But their internal implementations can be ugly.   While it would be nice to have them in this language, “there’s more than one way to do it.™”   As BrowserUK says (in so many words), I would not disabuse the Perl-5 language in order to do it in just this way.

For example, there are already closures in Perl ... the “coderefs” that were mentioned ... and these can be used to implement finite-state machines (FSMs) which will return a particular value each time they are called.   Presto, you have accomplished the intended effect, using the ordinary facilities that this programming language already offers you.   No, it’s not exactly the same thing, but a well-written implementation is clear.   Bloom where you are planted.

Anyhow, there are other threads on this, like Coroutines in Perl from back in 2004 ... and I can’t help but notice that, even “way back then,” the Perl-6 / Parrot people were telling us all how good it was going to be.   Someday.   ;-)


Comment on Re: RFC: Simulating Ruby's "yield" and "blocks" in Perl
Ruby's "yield" and "blocks" are not coroutines
by LanX (Abbot) on Apr 23, 2013 at 14:51 UTC
    Sorry I'm tired of repeating it, but even if Rubyistas claim it, yield / blocks are not coroutines, they are syntactic sugar for callbacks.

    And I think Matz is to blame for choosing the misleading term "yield" in this context.

    (Like Larry is to blame for some misleading "List" <-> "Array" terminology)

    And BTW Perl5 has coroutines, passing parameters is just ugly to implement and I'm not sure about the performance gain.

    Go take a look at the goto &sub syntax.

    Cheers Rolf

    ( addicted to the Perl Programming Language)

Re^2: RFC: Simulating Ruby's "yield" and "blocks" in Perl
by sundialsvc4 (Monsignor) on Apr 24, 2013 at 00:53 UTC

    Okay, take your word for it.   Just meant it as a colloquial, informal usage term.

    “Rubyista” ... that’s a fun mental-image to play with.   :-)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2014-04-21 03:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (490 votes), past polls