1
1
mirror of https://github.com/kanaka/mal.git synced 2024-09-20 01:57:09 +03:00
mal/tests/step5_tco.mal
2015-03-14 17:34:49 -05:00

31 lines
529 B
Plaintext

;; Testing recursive tail-call function
(def! sum2 (fn* (n acc) (if (= n 0) acc (sum2 (- n 1) (+ n acc)))))
(sum2 10 0)
;=>55
(def! res2 nil)
;=>nil
(def! res2 (sum2 10000 0))
res2
;=>50005000
;; Test recursive non-tail call function
(def! sum-to (fn* (n) (if (= n 0) 0 (+ n (sum-to (- n 1))))))
(sum-to 10)
;=>55
;;; no try* yet, so test completion of side-effects
(def! res1 nil)
;=>nil
;;; For implementations without their own TCO this should fail and
;;; leave res1 unchanged
(def! res1 (sum-to 10000))
res1
;=>nil