Skip to content

Instantly share code, notes, and snippets.

@mfollett
mfollett / fpblog-week1a.pl
Created August 30, 2010 01:28
Functional Programming Blog, week 1 example 1
sub { say 'Hello World!' };
@mfollett
mfollett / fpblog-week1b.pl
Created August 30, 2010 01:28
Functional Programming Blog, week 1 example 2
my $hello = sub { say 'Hello World!' };
@mfollett
mfollett / fpblog-week1c.pl
Created August 30, 2010 01:29
Functional Programming Blog, week 1 example 3
my $hello = sub { say 'Hello World!' };
$hello->();
@mfollett
mfollett / fpblog-week1d.pl
Created August 30, 2010 01:30
Functional Programming Blog, week 1 example 4
my $say = sub {say $_[0]};
$say->('Hello World!');
@mfollett
mfollett / fpblog-week1d.pl
Created August 30, 2010 01:30
Functional Programming Blog, week 1 example 5
my $outer = sub
{
my ($subject) = @_;
my $inner = sub
{
my ($salutation, $subject) = @_;
say "$salutation $subject!";
}
@mfollett
mfollett / fpblog-week1e.pl
Created August 30, 2010 01:33
Functional Programming Blog, week 1 example 6
my %evocations = (
say => sub { say shift; },
shout => sub { say uc shift; }
);
$evocations{say}->("Hello");
$evocations{shout}->("Hello");
@mfollett
mfollett / fpblog-week1f.pl
Created August 30, 2010 01:33
Functional Programming Blog, week 1 example 7
my $get_input = sub { my $ret = <>; chomp $ret; return $ret;};
my $request = sub { print "Please provide your age: "; $get_input->()};
my @prompts = (
$request,
$request,
sub { print "PLEASE PROVIDE YOUR AGE: "; $get_input->() },
sub { say "Fine, whatever, forget it."; return; }
);
my $age;
@mfollett
mfollett / fpblog-week2a.pl
Created August 30, 2010 03:08
functional programming blog, week 2 example 1
{
my $value = 11;
sub get_value { $value };
}
say get_value->(); # Succeeds in printing "11\n"
@mfollett
mfollett / fpblog-week2b.pl
Created August 30, 2010 03:08
functional programming blog, week 2 example 2
{
my $value = 11;
}
say $value;
@mfollett
mfollett / fpblog-week2c.pl
Created August 30, 2010 03:08
functional programming blog, week 2 example 3
my $fun
{
my $value = 42;
$fun = sub {$value};
}
say $fun->(); # prints "42\n"