4 ms·
If you look at it from the perspective of continuations then tail calls are very natural. A function call is always a goto, the only difference is that calls in
by jules 12y ago
If you look at it from the perspective of continuations then tail calls are very natural. A function call is always a goto, the only difference is that calls in tail position do not need to add extra data to the continuation.
- skybrian 12y agoOf course! But that still doesn't mean you should use them most of the time. Continuations are great for writing compilers but confusing to use elsewhere. Just like you don't normally write assembly (but it's necessary sometimes), you shouldn't normally use these exceptionally flexible but unstructured abstractions in a program you want other people to read. Instead you want to use constructs that are familiar and easy to reason about. It's hard to beat a for loop.
- glassx 12y agoBy continuations I believe Jules means Continuation-passing style, a popular optimization/intermediate format in compilers: http://en.wikipedia.org/wiki/Continuation-passing_style http://en.wikipedia.org/wiki/Continuation-passing_style
- jules 12y agoSure, whether you should use them is a software engineering question. I was merely speaking to their theoretical elegance, pointing out that from a continuation perspective tail call optimization isn't really an optimization, it's just the most natural way to implement procedure calls to begin with.