3 ms·
Scheme implementations have had to deal with this problem for a long time. (Of course, one can argue that languages with ordinary while loops have a similar pro
by vilhelm_s 12y ago
Scheme implementations have had to deal with this problem for a long time. (Of course, one can argue that languages with ordinary while loops have a similar problem, in that value of previous iterations of the loop get overwritten by later iterations).
You can alleviate it by hanging on to stack frames for a while. Scheme48 heap-allocates stack frames, and then relies on garbage collection to reclaim space from tail-calls, so this happens automatically. And MIT Scheme uses a ring-buffer to keep around the last 10-or-so frames. (Actually it is even nicer than that: it uses ringbuffer-of-ringbuffers to keep 10-or-so frames from each of the last 10-or-so non-tail recursive calls. So when debugging you can pop up the call stack, and then at each level examine the last couple interations of the loops done at that level).