diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/step5_tco.mal | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/step5_tco.mal b/tests/step5_tco.mal new file mode 100644 index 0000000..9054c74 --- /dev/null +++ b/tests/step5_tco.mal @@ -0,0 +1,27 @@ +;; 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 +(def! res1 (sum-to 10000))) +res1 +;=>nil + +;; 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 + |
