Skip to content

Commit 028e29e

Browse files
committed
add comment explaining the bug
1 parent 01e9fe1 commit 028e29e

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

tests/pyret/regression/tail-recursion-arg-order.arr

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,22 @@ examples:
2121
oops(4, 5) is working(4, 5)
2222
end
2323

24+
# When an argument is wrapped in a lambda to delay evaluation, mutation
25+
# in the tail recursion optimization will be unsound. Consider:
26+
2427
fun oops2(a, b):
2528
foo = lam(): a end
2629
if a == 1: b() else: oops2(1, foo) end
2730
end
2831

32+
# Note that
33+
#
34+
# b := lam(): a end
35+
# a := 1
36+
#
37+
# will make the second iteration eveluates to the mutated `a` which is wrong
38+
# An easy way to fix this is to simply disable TCO in this case
39+
2940
fun working2(a, b):
3041
foo = lam(): a end
3142
if a == 1: b() else: working2(1, foo) + 0 end

0 commit comments

Comments
 (0)