Browse Learn Clojure Foundations as a Java Developer

Recursive Functions in Clojure

Write recursive Clojure functions with obvious base cases, safe recursive steps, and clear stack trade-offs before reaching for loop/recur or reduce.

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

  • Writing Recursive Functions in Clojure
    Build recursive Clojure functions with base cases, smaller recursive steps, factorial and Fibonacci examples, and guidance for Java developers moving away from loop-first code.
  • Stack Safety for Recursive Functions
    Understand when recursive Clojure calls consume stack, when loop/recur can reuse a frame, and how to avoid stack overflow in Java-scale data work.
Revised on Saturday, May 23, 2026