Subject: | function thinks it was called with more arguments than it was |
The cycle.pl example in the distro
<http://cpansearch.perl.org/src/OSFAMERON/Sub-Curried-0.06/examples/cycle.pl>
does not work.
I broke down the steps and the problem is that the curried version of
scanl has some delusions about the number of args it is called with:
use strict; use warnings;
use Sub::Curried;
curry take ($count, $it) {
return map { $it->() } 1..$count;
}
curry cycle (@list) {
my @curr = @list;
return sub {
@curr = @list unless @curr;
return shift @curr;
};
}
curry scanl ($fn, $start, $it) {
my $curr = $start;
return sub {
my $ret = $curr;
$curr = $fn->($curr, $it->());
return $ret;
};
}
curry times ($x,$y) { $x * $y }
my $iterator = cycle( [2.5, 2, 2] ) ;
my $scanl_curried = scanl(times); # scanl called with 4 args, expected 3
at scanl2.pl line 30
my $r = $scanl_curried->(10, $iterator);
warn $iterator, $scanl_curried, $r;