FunctionalPerl
view release on metacpan or search on metacpan
lib/FP/Trampoline.pm view on Meta::CPAN
use warnings;
use warnings FATAL => 'uninitialized';
use Exporter "import";
our @EXPORT = qw(T TC trampoline);
our @EXPORT_OK = qw();
our %EXPORT_TAGS = (all => [@EXPORT, @EXPORT_OK]);
use FP::Carp;
sub T (&) {
bless $_[0], "FP::Trampoline::Continuation"
}
sub TC {
bless [@_], "FP::Trampoline::Call"
}
sub trampoline {
@_ == 1 or fp_croak_arity 1;
my ($v) = @_;
t/perl/goto-leak view on Meta::CPAN
$tot
}
}
}
# -----------------------------------------------------------
# variant using trampolines to implement tail call optimization, also
# confirming that the algorithm is sane and that it's got something to
# do with how perl handles goto &$coderef / stack memory or so.
sub T (&) {
bless $_[0], "TrampolineContinuation"
}
sub trampoline {
@_ == 1 or fp_croak_arity 1;
my ($v) = @_;
while (ref($v) eq "TrampolineContinuation") {
$v = &$v()
}
$v
( run in 2.080 seconds using v1.01-cache-2.11-cpan-5a3173703d6 )