Re:Joel Spolsky: Can your programming language do this?
by ericf on Saturday April 23, 2011 @08:42PM
(#2477988)
I implemented these examples in Ruby 1.9, would love to know if there are more efficient ways of doing some of these:
[ Parent
| on HN ]
Re:Joel Spolsky: Can your programming language do this?
by flatwhatson on Sunday April 24, 2011 @11:44AM
(#2479029)
Here's one more efficient way... use perl!
#!/usr/bin/perl
use Modern::Perl;
use List::Util 'reduce';
sub cook {
my ($i1, $i2, $f) = @_;
say "get the $i1";
$f->($i1);
$f->($i2);
}
cook "lobster", "water", sub { say "pot " . shift };
cook "chicken", "coconut", sub { say "boom " . shift };
my @a = (1, 2, 3);
map { say $_ * 2 } @a;
map { say $_ } @a;
sub my_sum {
reduce { $a + $b } 0, @_;
}
sub my_join {
reduce { $a . $b } "", @_;
}
say "sum " . my_sum(@a);
say "join " . my_join(@a);