▲ | skrishnamurthi 2 days ago | |||||||||||||||||||||||||
Tails calls are especially useful in languages with macros. You don't know what context you are in, you just generate the call that makes sense. If the call happens to be in tail-position, you get the benefit of it. Moreover, you can design cooperating macros that induce and take advantage of tail-position calls. Here's a simple example that motivates tail-calls that are not tail-recursive: https://cs.brown.edu/~sk/Publications/Papers/Published/sk-au... | ||||||||||||||||||||||||||
▲ | adityaathalye 2 days ago | parent [-] | |||||||||||||||||||||||||
Yeah, absent automatic TCO, we have to do it all, explicitly, by hand... `recur` and `trampoline`. recur: https://clojuredocs.org/clojure.core/recur
the recursion point to the values of the exprs.
trampoline: https://clojuredocs.org/clojure.core/trampoline
i.e. these emulate TCO, with similar stack consumption properties (they don't implement real TCO).(edit: formatting) | ||||||||||||||||||||||||||
|