defmodule Fib do def fib when 30 do parent self spawn fn send parent f

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
defmodule Fib do
def fib(n) when n > 30 do
parent = self()
spawn fn -> send parent, fib(n - 1) end
a = fib(n - 2)
receive do
x -> a + x
end
end
def fib(n) when n > 1, do: fib(n - 1) + fib(n - 2)
def fib(1), do: 1
def fib(0), do: 0
end
IO.puts Fib.fib(42)