Subject: | Acme::Lambda doesn't work. |
Acme::Lambda doesn't seems to work as documented. The following script
(almost cut and pasted from the documentation) is expected to print '16'
but actually prints '0':
makholm@makholm:~$ cat > lambda.pl
#!/usr/bin/perl -l
use Acme::Lambda;
my $square = lambda { $_ * $_ };
print $square->(4);
makholm@makholm:~$ perl lambda.pl
0
makholm@makholm:~$
Changing the lambda function so it says
sub lambda {
my $sub = shift;
return sub { local $_ = shift; $sub->() };
}
fixes the problem.
Subject: | lambda.patch |
--- Lambda.pm 2007-02-23 03:00:02.000000000 +0100
+++ LambdaBis.pm 2007-05-02 14:52:06.159328003 +0200
@@ -1,4 +1,4 @@
-package Acme::Lambda;
+package Acme::LambdaBis;
use warnings;
use strict;
@@ -11,7 +11,7 @@
sub lambda(&) {
my $sub = shift;
- return $sub;
+ return sub { local $_ = shift; $sub->() };
}
*λ = \λ