3 ms·
Right. In Clojure you'd use an explicit trampoline for stack-free mutual recursion.
by dewitt 13y ago
Right. In Clojure you'd use an explicit trampoline for stack-free mutual recursion.
- andrewvc 13y agoMutual TCO is really uncommon for what it's worth. Of you need it that bad a trampoline should suffice
- kvb 13y agoDirect mutual recursion is somewhat rare (but useful for encoding state machines, for instance). However, using continuation passing style (and tail calls to a continuation argument) to prevent stack overflow is a common idiom in some functional languages (e.g. when mapping over a binary tree).
- derefr 13y agoErlang uses mutual TCO everywhere. All actors/processes are state machines with the function they're in being their current state. To switch states, you just tail-call a new function (which doesn't have to be from the same module you were in.)