my @fn_refs = map {sub { print "$_\n"}} qw(foo bar baz);
for (@fn_refs) {
$_->();
}
####
CODE(0x8105f9c)
CODE(0x8105f9c)
CODE(0x8105f9c)
##
##
my @fn_refs = map {my $x=$_; sub { print "$x\n"}} qw(foo bar baz);
for (@fn_refs) {
$_->();
}
##
##
foo
bar
baz
##
##
sieve :: [Int] -> [Int] -> [Int]
-- sieve [] xs
-- Assuming that xs is a list of the form [2..max], returns a list of
-- primes between 2 and max. The first parameter is an accumulator
-- list.
--
-- This is a loose interpretation of the Sieve of Eratosthenes; instead
-- of marking composite numbers, we remove them.
sieve p [] = reverse p
sieve p (x:xs) = sieve (x:p) (filter (\t -> (rem t x /= 0)) xs)
##
##
factorial n
| n == 0 = 1
| otherwise = n * factorial (n-1)