A fork of Crisp for HARP
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
529 B

  1. ;; Testing recursive tail-call function
  2. (def! sum2 (fn* (n acc) (if (= n 0) acc (sum2 (- n 1) (+ n acc)))))
  3. (sum2 10 0)
  4. ;=>55
  5. (def! res2 nil)
  6. ;=>nil
  7. (def! res2 (sum2 10000 0))
  8. res2
  9. ;=>50005000
  10. ;; Test recursive non-tail call function
  11. (def! sum-to (fn* (n) (if (= n 0) 0 (+ n (sum-to (- n 1))))))
  12. (sum-to 10)
  13. ;=>55
  14. ;;; no try* yet, so test completion of side-effects
  15. (def! res1 nil)
  16. ;=>nil
  17. ;;; For implementations without their own TCO this should fail and
  18. ;;; leave res1 unchanged
  19. (def! res1 (sum-to 10000))
  20. res1
  21. ;=>nil