Skip to content

Commit 461d887

Browse files
committed
Fix usage of running codes
1 parent db748ba commit 461d887

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

getting-started/recursion.markdown

+8-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ defmodule Math do
6666
end
6767
end
6868

69-
Math.sum_list([1, 2, 3], 0) #=> 6
69+
IO.puts Math.sum_list([1, 2, 3], 0) #=> 6
7070
```
7171

7272
We invoke `sum_list` with the list `[1, 2, 3]` and the initial value `0` as arguments. We will try each clause until we find one that matches according to the pattern matching rules. In this case, the list `[1, 2, 3]` matches against `[head|tail]` which bounds `head` to `1` and `tail` to `[2, 3]`; `accumulator` is set to `0`.
@@ -96,8 +96,14 @@ defmodule Math do
9696
[]
9797
end
9898
end
99+
```
100+
101+
```bash
102+
iex math.exs
103+
```
99104

100-
Math.double_each([1, 2, 3]) #=> [2, 4, 6]
105+
```iex
106+
iex> Math.double_each([1, 2, 3]) #=> [2, 4, 6]
101107
```
102108

103109
Here we have used recursion to traverse a list doubling each element and returning a new list. The process of taking a list and _mapping_ over it is known as a _map algorithm_.

0 commit comments

Comments
 (0)