2 ms·
I find this post by a language designer perplexing. The fool-proof way of getting proper tail recursion is transformation of the program into a form in which a
by owinebarger 17y ago
I find this post by a language designer perplexing.
The fool-proof way of getting proper tail recursion is transformation of the program into a form in which all control flow is expressed in the form of function calls in tail position, including the returns. The standard target is continuation passing style. In this form, the stack-building constructions appear directly in the code. The ones that are merely administrative (bookkeeping the stack without real utility) can be eliminated at compile-time. Those administrative constructs include the ones that would make tail-calls use "stack space".
Guido refers to how every "stack frame" is heap allocated so they can't be reused. That's a design choice in the compiler's closure conversion mechanism.
Guido also refers to stack traces and exceptions, but these would be explicitly represented in the all-tail-call form of the program as well. What he means is that the language has no tail positions because there is always implicit work to be done in the language as he defines the semantics. That seems like an odd thing to brag about, but that's what he's doing.
But then I'm one of the programmers who has been permanently warped by learning about CPS, and I thoroughly rely on tail recursion being available and implemented efficiently.