Merge pull request #530 from mpritham/master
[jackhill/mal.git] / impls / tests / step5_tco.mal
CommitLineData
4e7296f9
JM
1;; Testing recursive tail-call function
2
3(def! sum2 (fn* (n acc) (if (= n 0) acc (sum2 (- n 1) (+ n acc)))))
4
9e8f5211
JM
5;; TODO: test let*, and do for TCO
6
4e7296f9
JM
7(sum2 10 0)
8;=>55
9
10(def! res2 nil)
11;=>nil
12(def! res2 (sum2 10000 0))
13res2
14;=>50005000
15
16
b25e3d29
JFI
17;; Test mutually recursive tail-call functions
18
19(def! foo (fn* (n) (if (= n 0) 0 (bar (- n 1)))))
20(def! bar (fn* (n) (if (= n 0) 0 (foo (- n 1)))))
21
22(foo 10000)
23;=>0