-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrecursion.lox
39 lines (35 loc) · 906 Bytes
/
recursion.lox
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
fun decrement_loop(name, n) {
print name;
print n;
if (n == 1) return n;
var x = n-1;
var sum;
var left;
var right;
left = decrement_loop("left", x) ;
right = decrement_loop("right", x);
sum = left + right;
// General bug: relates to inline local variable declarations
// TODO: Try to find a simpler repro
//
// var sum = decrement_loop("left", x) + decrement_loop("right", x);
// !=
// var sum;
// sum = decrement_loop("left", x) + decrement_loop("right", x);
//
// ... similarly ...
//
// var sum;
// var left;
// var right;
// left = decrement_loop("left", x) ;
// right = decrement_loop("right", x);
// sum = left + right;
// !=
// var sum;
// sum = decrement_loop("left", x) + decrement_loop("right", x);
print "sum";
print sum;
return sum;
}
print decrement_loop("start", 3);