Next |
Functional Programming in Perl |
11 |
# Perl version # SML version
sub outer { fun outer x' =
my $x = shift; let val x = ref x'
my $inner = sub { fun inner y =
my $y = shift;
if ($y == 0) { $x++ } ((if y = 0 then x:= !x+1 else ());
return $x + $y; b + !x)
}; in
return $inner; inner
} end
my $d = outer(100); val d = outer 100
my $e = outer(10); val e = outer 10
$d->(3); # returns 103
$e->(3); # returns 13
$d->(0); # returns 101
$d->(3); # returns 104
$e->(3); # returns 13
Next |
|
Copyright 2005 M. J. Dominus |