Perl is somewhat functional itself -- if the concept, "functional", which we're talking about, mainly means using functions as first-class objects instead of wiping almost all side effects out. However, lacking of sugar such as useful prototypes, pattern matching, or list comprehensions makes Perl less attractive in some functional situation (for fun, perhaps).
There are a few attempts I made to achieve a better experience when programming perl for fun. For example:
#!/usr/bin/env perl
use HOI::Comprehensions;
use HOI::Match;
sub slowsort {
HOI::Match::pmatch(
'nil' => sub { [] },
'pivot :: unsorted' =>
sub {
my $left = HOI::Comprehensions::comp( sub { $x }, x => $un
+sorted )->( sub { $x <= $pivot } );
my $right = HOI::Comprehensions::comp( sub { $x }, x => $u
+nsorted )->( sub { $x > $pivot } );
[ @{slowsort($left->force)}, $pivot, @{slowsort($right->fo
+rce)} ]
},
)->(@_)
}
my $res = slowsort [3, 4, 1, 2, 5, 6];
print @$res, "\n";
where HOI::Match and HOI::Comprehensions are used to give a simple description of the whole computation. It should be noted that the code is not so strict since it assumes the existence of local variables. Scopes are dynamic, and bound variables are bound by names, as the ones in a typical lambda calculus theory.
It is still not clear to me whether such sugar ideas are welcomed or not. Any suggestion or criticism is welcomed. I am looking forward for your replies.