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
v3 is current, though str.format() was added in late v2 releases for compatibility (printf style interpolation is to be deprecated some time but I'll use it below as an example...). Here's the decorated version as suggested:
Edit: trimmed some code
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 | |
|
In Section
Meditations