Search⌘ K

Recursion and Effects

Explore recursion concepts including tail recursion and its optimization in functional programming. Understand the impact of side effects and shared state, and learn techniques to manage them for predictable, maintainable Clojure code.

Recursion

In functional programming, we say we prefer recursion over looping to iterate over collections. That’s because looping relies on a state to iterate over a collection, while in recursion, we don’t need to do that. Plus, it fits better with the functional programming guidelines.

A recursive call happens when it’s done inside the scope of the function being called. So basically, it’s a function invoking itself, letting the logic be repeated until it reaches the base case. A well-known challenge in introducing recursion is the calculation of the factorial formula:

However, to better understand recursion, we need to ...