Merge pull request #532 from dubek/vhdl-fix-defmacro
[jackhill/mal.git] / impls / tests / step5_tco.mal
1 ;; Testing recursive tail-call function
2
3 (def! sum2 (fn* (n acc) (if (= n 0) acc (sum2 (- n 1) (+ n acc)))))
4
5 ;; TODO: test let*, and do for TCO
6
7 (sum2 10 0)
8 ;=>55
9
10 (def! res2 nil)
11 ;=>nil
12 (def! res2 (sum2 10000 0))
13 res2
14 ;=>50005000
15
16
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