Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

There are some subtle differences, which makes the whole sense.

Classic version has a self-evident clarity and familiar shape of a recursive function, which utilizes TCO.

Perfection is achieved when there is nothing more to cut off, not when there is nothing more to pile up.)



Is the classic one actually going to be able to leverage tail-call elimination? Obviously it could be refactored to make a tail-recursive call, but correct me if I'm wrong, it wouldn't be automatic.

After refactoring it, the tail-recursive version would be a bit harder to read than the naive implementation. In a sense the Clojure code is in the same boat, it's just that the optimizations are more complicated, because it's not working with singly linked lists in the "address register" and "decrement register".


So the classic version works in a lazy fashion, for example with infinite structures? Keep in mind that Clojure is a strict language by default.


Nothing more to cut off, including runtime and memory usage.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: