Closed cianoc closed 6 years ago
Hey Cian,
;; not tail recursive (bind-func fact1 (lambda (n) (if (<= n 0) 1 (* n (fact1 (- n 1))))))
;; tail recursive (bind-func fact2 (lambda (nn) (let ((f (lambda (n k) (if (<= n 0) k (f (- n 1) (* (i64tod n) k)))))) (f nn 1.0))))
From: cianoc Sent: Tuesday, 2 January 2018 11:54 AM To: digego/extempore Cc: Subscribed Subject: [digego/extempore] Recursion causes a segfault (#309)
(bind-func fact (lambda (n) (let ((p (- n 1))) (if (<= n 0) (1) (* n (fact p)))))) (bind-func fact3 (lambda (n) (let ((total 1)) (while (> n 0) (set! total (* total n)) (set! n (- n 1))) (println total)))) Running($ (println (fact 1600000)))results in a segfault. In contrast running:(fact3 1600000)
does not.
This would suggest that tail optimization isn't implemented for xtlang.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.
Ah gotcha. I will close this issue once I've got something written about it.
If I had a nickel for every time I'd made that mistake I'd have a lot of nickels by now.
Running
($ (println (fact 1600000)))
results in a segfault. In contrast running:(fact3 1600000)
does not.This would suggest that tail optimization isn't implemented for xtlang.