by Eily (Monsignor)
 on Jun 17, 2013 at 17:59 UTC Need Help??

```use v5.14;

#my \$fact = sub { (sub { goto &{\$_[0]} })->(sub { \$_[1] ? \$_[1] * \$_[0
+](\$_[0], \$_[1]-1) : 1 }, \$_[0]) };
#my \$fact = sub { (sub { \$_[0](\$_[0], \$_[1]) })->(sub { \$_[1] ? \$_[1]
+* \$_[0](\$_[0], \$_[1]-1) : 1 }, \$_[0]) };

my \$auto_fact = sub
{
my (\$self, \$value) = @_;
return 1 unless \$value > 1;
return \$value * \$self->(\$self, \$value - 1);
};

my \$auto_fib = sub
{
my (\$self, \$rank) = @_;
return 1 unless \$rank > 1;
return \$self->(\$self, \$rank - 1) + \$self->(\$self, \$ra
+nk - 2);
};

say "Test auto fact: \$_!=", \$auto_fact->(\$auto_fact, \$_) for 5, 6, 10;
say "Test auto fib: ", join ", ", map { \$auto_fib->(\$auto_fib, \$_) } 0
+..10;

my \$transformator = sub
{
my (\$auto_fun,) = @_;
return sub { \$auto_fun->(\$auto_fun, @_) }
};

*fib = \$transformator->(\$auto_fib);
say "Test fib: ", join ", ", map fib(\$_), 0..10;

*fact = (sub { my (\$auto_fun,) = @_; sub { \$auto_fun->(\$auto_fun, @_)
+} })->( sub { my (\$self, \$value) = @_; \$value ? \$value * \$self->(\$sel
+f, \$value - 1) : 1 } );
say "Test fact: \$_!=", fact(\$_) for 3, 4, 5;

Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2019-09-21 09:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
The room is dark, and your next move is ...

Results (271 votes). Check out past polls.

Notices?