Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 31 lines (22 sloc) 0.655 kB
b159547 [t] and [t/spec]
moritz authored
1 use v6;
2
3 use Test;
4
5 =begin desc
6
7 Closure over parameters of outer subs, as per
8 # L<S04/The Relationship of Blocks and Declarations/"Every block is a
9 # closure">
10 # L<S06/Dynamically scoped subroutines>
11
12 =end desc
13
14 plan 4;
15
16 sub factorial (Int $n) {
17 my sub facti (Int $acc, Int $i) {
18 return $acc if $i > $n;
19 facti($acc * $i, $i + 1);
20 }
21 facti(1, 1);
22 } ;
23
24 is factorial(0), 1, "closing over params of outer subs (0)";
25 is factorial(1), 1, "closing over params of outer subs (1)";
246ed8d @coke pugs fudges
coke authored
26 #?pugs 2 todo
b159547 [t] and [t/spec]
moritz authored
27 is factorial(2), 2, "closing over params of outer subs (2)";
28 is factorial(3), 6, "closing over params of outer subs (3)";
29
30 # vim: ft=perl6
Something went wrong with that request. Please try again.