First-class functions: Difference between revisions

(→‎{{header|Tcl}}: Version that works more reliably)
(→‎{{header|Python}}: Added Perl.)
Line 226:
endfor</lang>
 
 
=={{header|Perl}}==
<lang perl>use Math::Complex ':trig';
 
my $cube = sub {shift()**3};
my $croot = sub {shift()**(1/3)};
 
sub compose
{my ($f, $g) = @_;
return sub {$f->($g->(@_));};}
 
my @flist1 = (\&Math::Complex::sin, \&Math::Complex::cos, $cube);
my @flist2 = (\&asin, \&acos, $croot);
 
foreach (0 .. $#flist1)
{print compose($flist1[$_], $flist2[$_])->(.5), "\n";}</lang>
 
=={{header|Python}}==
845

edits