in reply to Re^4: RFC: Simulating Ruby's "yield" and "blocks" in Perl (Python)
in thread RFC: Simulating Ruby's "yield" and "blocks" in Perl
I don't really see a win with this style, though, over giving test a parameter, and just using standard function calls (I had a little play with coroutines on the way but that's really overkill for this).def rubyyielder(gen): def wrapped_gen(block): for elem in gen(): block(elem) return wrapped_gen @rubyyielder def test(): print("In test") yield 1 print("back in test") yield 2 @test def _(a): print("You are in block %s" % a)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: RFC: Simulating Ruby's "yield" and "blocks" in Perl (Python)
by LanX (Saint) on Apr 26, 2013 at 14:00 UTC | |
by MonkOfAnotherSect (Sexton) on Apr 26, 2013 at 15:13 UTC | |
by LanX (Saint) on Apr 26, 2013 at 17:54 UTC | |
by MonkOfAnotherSect (Sexton) on Apr 27, 2013 at 14:11 UTC | |
by LanX (Saint) on Apr 27, 2013 at 15:07 UTC | |
|