5 ms·
I don't like this in a lot of languages. But it's not a showstopper, just an annoyance to be aware of. That said, there should be no reason not to have your n
by drblast 15y ago
I don't like this in a lot of languages. But it's not a showstopper, just an annoyance to be aware of.
That said, there should be no reason not to have your new modern programming language support tail calls. It's short-sighted, and can negatively affect more than just the trivial recursive case.
So, new programming language inventors, if you're reading this, support tail call optimization and proper tail recursion from the beginning. Your language will be better for it.
- bascule 15y ago> there should be no reason not to have your new modern programming language support tail calls There's many valid reasons not to support TCO. The first one that comes to mind: it makes generating stack traces more difficult. Another reason: the JVM doesn't natively support TCO. This means to implement it you'll either need to use a trampoline (e.g. Erjang) or convert recursion to iteration (e.g. Clojure) The latter isn't too difficult, but when tail recursion merely provides an alternate syntax for iteration, and mutual tail recall recursion isn't supported, is there really as much of a point if your language is something like Ruby and already provides multiple means of iteration?
- gioele 15y ago> There's many valid reasons not to support TCO. The first one that comes to mind: it makes generating stack traces more difficult. > Another reason: the JVM doesn't natively support TCO. This means to implement it you'll either need to use a trampoline (e.g. Erjang) or convert recursion to iteration (e.g. Clojure) So you avoid a 35 years old functionality that makes many procedures smaller, faster and more understandable just to make the compilers simpler? Isn't this one of the usual tradeoffs where you (should) prefer having the compiler doing the boring and dirty job of converting a recursion to a loop, with all the bookkeeping of maintaining the state and making it thread-safe, simplifying the life of the application programmer at the expenses of the compiler programmer?
- anonymoushn 15y agoClojure doesn't really implement tail calls - if you need tail calls for several mutually recursive functions it becomes nontrivial to express because the looping constructs just won't do that for you.