## With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

No credit card required

# Recursion

The best way to tackle programming problems is to use the well-tested strategy of divide and conquer to break the problem into a number of simpler subproblems. By joining together the solutions of several simple problems, you solve the bigger one without even realizing it! Let’s try this approach by taking a list of integers and adding 1 to every element in the list. Because Erlang is a single assignment language, we have to create a new list, in which we will store the result.

We will name the function bump/1 and divide the problems into smaller tasks that are easier to solve, implementing one clause at a time. If the old list is empty, the new one should also be empty. The following function clause takes care of this case:

bump([]) -> [];

The second possibility is that the list contains at least one element. If so, we split the list to a head and a tail. We take the head and create a new list whose head is the head of the old list incremented by 1: