Higher order perl
Upcoming SlideShare
Loading in...5
×
 

Higher order perl

on

  • 3,023 views

Hokkaido.pm #4

Hokkaido.pm #4

Statistics

Views

Total Views
3,023
Views on SlideShare
1,476
Embed Views
1,547

Actions

Likes
2
Downloads
4
Comments
1

6 Embeds 1,547

http://hokkaido.pm.org 1325
http://www.skyarc.co.jp 217
http://twitter.com 2
https://www.skyarc.co.jp 1
http://translate.googleusercontent.com 1
http://www.mefeedia.com 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
  • mement とか strategy とかもクロージャを使うと簡単にかけるようになるものの、たいていメンテしにくくなるのでやめた方が無難でござる(経験的に)。
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Higher order perl Higher order perl Presentation Transcript

  • 2011 2 19
  • 2011 2 19
  • 2011 2 19
  • 2011 2 19
  • 2011 2 19
  • 2011 2 19
  • 2011 2 19
  • 2011 2 19
  • 2011 2 19
  • 2011 2 19
  • 2011 2 19
  • 2011 2 19
  • 2011 2 19
  • 2011 2 19
  • 2011 2 19
  • 2011 2 19
  • 2011 2 19
  • 2011 2 19
  • 2011 2 19
  • 2011 2 19
  • 2011 2 19
  • 2011 2 19
  • 2011 2 19
  • 2011 2 19
  • 2011 2 19
  • 2011 2 19
  • 2011 2 19
  • 2011 2 19
  • 2011 2 19
  • 2011 2 19
  • 2011 2 19
  • 2011 2 19
  • 2011 2 19
  • use strict; # my $add = sub { $_[0] + $_[1] }; # $add->(3, 4); # => 7 use strict; sub add { $_[0] + $_[1]; } add(2,4);2011 2 19
  • use strict; my $c = 3 my $add = sub { $_[0] + $c}; $add->(4); # => 72011 2 19
  • use strict; my $c = 3 my $proc = sub { $c++ }; $proc->(); # 3 $proc->(); # 4 $proc->(); # 52011 2 19
  • use strict; sub add { $_[0] + $_[1]; } my $func = ¥&add; $func->(3, 4); # => 72011 2 19
  • use strict; # sub generate { my ($a, $b) = @_; sub { $a + $b }; } generate(3, 4)->(); # => 72011 2 19
  • use strict; use feature qw(say); # sub generate { my ($num) = @_; sub { $num++ }; } my $fun = generate(2); say $fun->(); # => 2 say $fun->(); # => 3 my $fun2 = generate(2); say $fun2->(); # => 2 say $fun2->(); # => 32011 2 19
  • 2011 2 19
  • 2011 2 19
  • use strict; sub each_line { my ($file, $proc) = @_; open my $fh “<$file” or return; while(my $line = <$fh>) { $proc->($line); } close($fh); } each_line(‘aaa.txt’, sub { print $_[0] } );2011 2 19
  • use strict; sub each_line (&@) { my ($proc, $file) = @_; open my $fh, "<$file" or return; while(my $line = <$fh>) { $proc->($line); } close($fh); } each_line { print $_[0]; } (lex.pl) ;2011 2 19
  • 2011 2 19
  • use strict; my $table = { ‘left’ => sub { print ‘left’ }, ‘right’ => sub { print ‘right’ }, }; sub dispatch { my ($mode) = @_; my $func = $table->{$mode}; $func && $func->(); } dispatch(‘left’);2011 2 19
  • 2011 2 19
  • use strict; use Log::Dispatch; my $logger = Log::Dispatch->new; sub generate_logger { my ($ip) = @_; sub { $logger->info(“$ip : $_[0]“) }; } $custom_logger = generate_logger (‘192.168.1.1’); $custom_logger->(“msssssg”) # => “192.168.1.1 : msssssssg”2011 2 19
  • sub patial_add { my ($a) = @_; sub { add( $a + $_[0] ) }; } sub add { $_[0] + $_[1]; } my $func = patial_add(2); $func->(5); # => 72011 2 19
  • 2011 2 19
  • use strict; package Collection; sub new { my $class = shift; bless {data => @_}, $class; } sub iter { my $self = shift; my $counter = 0; sub { $self->{data}[$counter++] }; } package main; my $iter = Collection->new(1, 2)->iter; say $iter->(); # => 1 say $iter->(); # => 22011 2 19
  • 2011 2 19
  • use strict; use feature qw(say); # 1 .. my $infinite_list = sub { my $c = 1; sub { $c++; } }; # 100 my $num_list = $infinite_list->(); for my $i (0..100) { say $num_list->(); }2011 2 19
  • 2011 2 19
  • 2011 2 19
  • my $var = 12; sub func { say $var; } sub test { my $var = 19; func(); } test(); # => 12 func(); # => 122011 2 19
  • local $var = 12; sub func { say $var; } sub test { local $var = 19; func(); } test(); # => 19 func(); # => 122011 2 19
  • 2011 2 19
  • 2011 2 19
  • 2011 2 19
  • 2011 2 19
  • 2011 2 19
  • 2011 2 19
  • 2011 2 19
  • 2011 2 19
  • 2011 2 19
  • 2011 2 19
  • 2011 2 19