line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Acme::Lambda; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
67402
|
use 5.008; |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
96
|
|
4
|
3
|
|
|
3
|
|
18
|
use warnings; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
69
|
|
5
|
3
|
|
|
3
|
|
16
|
use strict; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
104
|
|
6
|
3
|
|
|
3
|
|
2724
|
use utf8; |
|
3
|
|
|
|
|
25
|
|
|
3
|
|
|
|
|
13
|
|
7
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
106
|
use base qw(Exporter); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
785
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our @EXPORT = qw(lambda λ); |
11
|
|
|
|
|
|
|
our @EXPORT_OK = @EXPORT; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub lambda(&) { |
14
|
5
|
|
|
5
|
0
|
1740
|
my $sub = shift; |
15
|
5
|
|
|
5
|
|
28
|
return sub {local $_ = $_[0]; $sub->(@_)}; |
|
5
|
|
|
|
|
1003
|
|
|
5
|
|
|
|
|
16
|
|
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
*λ = \λ |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=encoding utf8 |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 NAME |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
Acme::Lambda - Perl with lambdas! |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 VERSION |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
Version 0.03 |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=cut |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head1 SYNOPSIS |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
Acme::Lambda brings the power of lambda to perl! It exports lambda and |
37
|
|
|
|
|
|
|
λ subroutines that take a code block and return it. |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
use Acme::Lambda; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
my $square = lambda { $_ * $_ }; |
42
|
|
|
|
|
|
|
print $square->(4); # 16 |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
use utf8; |
45
|
|
|
|
|
|
|
my $cube = λ {$_ * $_ * $_}; |
46
|
|
|
|
|
|
|
print $cube->(3); # 27 |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# The sub can also access its full argument list through @_ |
49
|
|
|
|
|
|
|
my $add = lambda {$_[0] + $_[1] } ; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
print $add->(3,4); # 7 |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 EXPORT |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
By default, lambda and λ. |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
C |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 AUTHOR |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
Nelson Elhage, C<< >> |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head1 BUGS |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
Please report any bugs or feature requests to |
66
|
|
|
|
|
|
|
C, or through the web interface at |
67
|
|
|
|
|
|
|
L. |
68
|
|
|
|
|
|
|
I will be notified, and then you'll automatically be notified of progress on |
69
|
|
|
|
|
|
|
your bug as I make changes. |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
I |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 LICENSE |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
Acme::Lambda is Copyright 2007 Best Practical Solutions, LLC. |
78
|
|
|
|
|
|
|
Acme::Lambda is distributed under the same terms as Perl itself. |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=cut |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
1; # End of Acme::Lambda |