defmodule Sum do def sum(1), do: 1 def sum(n), do: n + sum(n - 1) end
^o^ > iex Eshell V8.0 (abort with ^G) Interactive Elixir (1.3.4) - press Ctrl+C to exit (type h() ENTER for help) iex(1)> c "practice_6_4.exs" [Sum] iex(2)> Sum.sum(10) 55
takatoh's blog – Learning programming languages.
defmodule Sum do def sum(1), do: 1 def sum(n), do: n + sum(n - 1) end
^o^ > iex Eshell V8.0 (abort with ^G) Interactive Elixir (1.3.4) - press Ctrl+C to exit (type h() ENTER for help) iex(1)> c "practice_6_4.exs" [Sum] iex(2)> Sum.sum(10) 55