in reply to Re^7: RFC: Simulating Ruby's "yield" and "blocks" in Perl (Python)
in thread RFC: Simulating Ruby's "yield" and "blocks" in Perl
I was just surprised that you need two decorators!
I thought you could simply do something like
test(def _(x): print("You are in block %s" % x))
(like test sub { print("You are in block $_[0]") } in Perl)
Just to get closer to the Ruby feeling and to achieve this
>>> def _(x): ... print("You are in block %s" % x) ... >>> test(_) In test You are in block 1 back in test You are in block 2 test lambda a: print("You are in block %s" % a)
But one needs decorators to manipulate a literal function.
Obviously, there is only this way to do it.
FWIW Python decorators could quite easily be simulated in Perl with attributes.
I will post this soon (if I can't find it already on CPAN) =)
Cheers Rolf
( addicted to the Perl Programming Language)
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^9: RFC: Simulating Ruby's "yield" and "blocks" in Perl (Python)
by MonkOfAnotherSect (Sexton) on Apr 27, 2013 at 14:11 UTC | |
by LanX (Saint) on Apr 27, 2013 at 15:07 UTC | |
by MonkOfAnotherSect (Sexton) on Apr 28, 2013 at 00:45 UTC | |
by LanX (Saint) on Apr 28, 2013 at 13:10 UTC |