Skip to content

Instantly share code, notes, and snippets.

@tfkd
Created August 19, 2012 03:55
Show Gist options
  • Save tfkd/3391792 to your computer and use it in GitHub Desktop.
Save tfkd/3391792 to your computer and use it in GitHub Desktop.
むりやりperlで関数型言語っぽくappend書いてみた
#!/usr/bin/env perl
use strict;
use warnings;
my $append; $append = sub {
my ($X, $Y) = @_;
if (0 == scalar @$X) {
return $Y;
}
else {
my $A = shift @$X;
my $Z = $append->($X, $Y);
unshift @$Z, $A;
return $Z;
}
};
print join " ", @{$append->([1,2,3],[4,5,6])};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment