26 ms·
About that factorial code in Clojure, I wish in reality one could write beautiful recursive code like that without blowing the stack for large inputs, one of my
by Scarbutt 8y ago
About that factorial code in Clojure, I wish in reality one could write beautiful recursive code like that without blowing the stack for large inputs, one of my main grips with Clojure.
- cr__ 8y agoSure you can, you just have to make the recursive call explicit: https://clojurebridge.github.io/community-docs/docs/clojure/recur/ https://clojurebridge.github.io/community-docs/docs/clojure/... This has the nice side effect of preventing you from writing a function that you think will be tail call optimized but really isn’t—the compiler will yell if your call to `recur` isn’t in tail position. The code in the article doesn’t have the recursive call in tail position anyway, so it’s not like other languages would be able to optimize it away.