Vend <vend82@virgilio.it> wrote:
+---------------
| Tail call optimization is an implementation technique of tail calls on
| stack-based architectures that removes the stack frame of the caller
| procedure when the callee is invoked.
|
| Taill call optimization can be used to implement proper tail
| recursion, but it isn't required.
| Chicken Scheme, for instance, provides proper tail recursion without
| implementing it as tail call optimization.
+---------------
Small quibble: Chicken Scheme *does* "remove the stack frame of the
caller procedure when the callee is invoked", just not at the time
of the call. Instead, all of the outstanding stack frames of calling
procedures are removed "en masse" in one shot when a garbage collection
is triggered by the C stack growing too large... which (after moving
live data out of the stack into the heap) finishes with a "longjmp()"
far up the stack [which is what actually removes the caller frames].
But you are correct in principle that TCO at the call site per se
is not required for unbounded safe-for-space tail-call chains, e.g.,
a trampoline loop can provide the latter without the former.
-Rob
-----
Rob Warnock <rpw3@rpw3.org>
627 26th Avenue <URL:http://rpw3.org/>
San Mateo, CA 94403 (650)572-2607