- or download this
#! perl -l
...
# f(x)
print $g->("x");
# g(x)
- or download this
sub compose2 {
my ($f, $g) = @_;
sub { $f->( $g->(@_) ) }
}
- or download this
my $h = compose2( $f, $g );
print $h->("x");
# f(g(x))
- or download this
sub foldl {
my $f = shift;
...
sub compose {
foldl( \&compose2, @_ )
}
- or download this
print compose( $f,$f,$f,$f,$f,$f,$g )->("x");
# f(f(f(f(f(f(g(x)))))))
...
print compose( ($add1) x 4 )->(0);
# 4