Elixir - sum of list values with recursion

elixir, erlang

Solution

You need to use lowercase letters for variable and functions names. Identifiers starting with uppercase are reserved for modules:

defmodule Mth do 

  def sum_list([]) do 
    0
  end

  def sum_list([h|t]) do
    h + sum_list(t)
  end

end

iex> IO.puts Mth.sum_list([1, 2, 300])
303
:ok

Problem

Just trying to do simple sum of list values. ``` defmodule Mth do def sum_list([]) do 0 end def sum_list([H|T]) do H + sum_list(T) end end IO.puts Mth.sum_list([1, 2, 300]) ``` But I get this error: ``` **(FunctionClauseError) no function clause matching in Mth.sum_list/1 pokus.ex:3: Mth.sum_list([1, 2, 300]) pokus.ex:14: (file) (elixir) src/elixir_lexical.erl:17: :elixir_lexical.run/2 (elixir) lib/code.ex:316: Code.require_file/2** ```

Original source