defmodule TakeANumber do
def start() do
spawn(fn -> loop(0) end)
end
defp loop(number) do
new_state = receive do
:stop -> exit(:ok)
{:report_state, pid} -> send(pid, number)
{:take_a_number, pid} -> send(pid, number + 1)
_ -> number
loop(new_state)