Michele Dondi writes: > Quite similarly, for example, I'd like to have a fold() function like the > one that is available in many functional programming languages, a la: > > my $tot = fold 0, { + }, 1..10; # 55 > my $fact = fold 1, { * }, 2..5; # 120 > > (i.e. please DO NOT point out that there other WTDI: it's obvious that > there are...)
Well, Perl 6 is coming with one of those as a builtin, called C<reduce> (see List::Util). But you can't quite use a shorthand syntax like yours. You have to say either: my $tot = reduce { $^a + $^b } 1..10; # 55 Or: my $tot = reduce &operator:+ <== 1..10; # 55 (The <== was added as documentation; it could have been a comma as well). Luke