3 ms·
I think calling it an "optimization" is unfair. You don't call while loops that run in constant space an optimization, do you? Without support for proper tail
by tikhonj 15y ago
I think calling it an "optimization" is unfair. You don't call while loops that run in constant space an optimization, do you?
Without support for proper tail calls, a large range of otherwise valid recursive programs does not work. So, in a very real sense, supporting proper tail recursion changes the semantics of the language, letting you certain programs more easily.
- lmkg 15y agoI've always been a little bit uncomfortable with the line of reasoning that TCO is a semantics change. For any list of programs (and inputs) that would return with TCO but would otherwise fail with a memory error, there is some amount of memory additional memory you could add that would also cause the program to return. I don't normally consider buying RAM to change the semantics of my programming language. It certainly changes what's practical to do with constrained resources in a language, but the same could be said of most things that are considered "optimizations." On the other hand, I do sympathize with the idea that TCO is somehow different that most optimizations. It potentially turns O(\inf) memory usage into O(1). If anything, it feels like an algorithmic optimization more than the implementation optimizations that compilers are generally limited to.
- ryanpetrich 15y agoOn systems that have a limited stack size, it is a semantics change. Usually this is more limiting than memory or address space. Split stacks are one workaround, but can have a performance penalty of their own.
- deleted 15y ago[deleted]
- pwpwp 15y agoI prefer tail-call elimination.