Skip to content

Instantly share code, notes, and snippets.

@ishiduca
Created October 28, 2011 08:33
Show Gist options
  • Save ishiduca/1321875 to your computer and use it in GitHub Desktop.
Save ishiduca/1321875 to your computer and use it in GitHub Desktop.
λ式をPerlで表現するメモ
#!/usr/bin/env perl -l
use strict;
use warnings;
# fx:=x+1;
sub f {
local $_ = shift;
$_+1;
}
print f(3);
# f:=^x.x+1;
my $f = sub {
local $_ = shift;
$_+1;
};
print $f->(3);
# f:^x y.x+y;
my $plus = sub {
my($x, $y) = @_;
$x + $y;
};
print $plus->(1,2);
# f:^x.(^y.x+y);
my $cplus = sub {
my $x = shift;
sub {
my $y = shift;
$x + $y;
};
};
print $cplus->(1)->(2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment