Browse Clojure Foundations for Java Developers

Recursive Functions

Writing recursive functions in Clojure, and what to watch for with the call stack.

A recursive function is just a function that calls itself. In Clojure, the important question is not “can I write recursion?” but “is this recursion safe and readable?”

What to pay attention to

  • Always make the base case obvious.
  • Prefer tail recursion (with recur) when you would otherwise risk stack overflow.
  • For linear iteration over a collection, prefer reduce or sequence functions unless recursion is clearer.

Java mental model: many “recursive” problems in Java are solved with loops. In Clojure, the first choice is often sequence transformations, and explicit recursion is reserved for when it improves clarity.

This section helps you write recursion that future readers can trust.

In this section

Revised on Friday, April 24, 2026