Recursion Revisited
Clojure works very hard to balance the power of functional programming with the reality of the Java Virtual Machine. One example of this is the well-motivated choice of explicit TCO through loop/recur.
But blending the best of two worlds always runs the risk of unpleasant compromises, and it certainly makes sense to ask the question “Does Clojure contain hidden design compromises that, while not obvious on day one, will bite me later?”
This question is never fully answerable for any language, but let’s consider it by exploring some more complex recursions. First we will look at mutual recursion.
A mutual recursion occurs when the recursion bounces between two or more functions. Instead of A calls A calls A, you have ...
Get Programming Clojure, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.