title: Elixir default parameters for named functions with multiple clauses
body: <p>I have trouble understanding how default parameters interact with multiple clauses in named functions. It boils down to, why does the following snippet work?</p>
  
  <pre><code>defmodule Lists do
  
    def sum([], total \\ 0), do: total
    def sum([h|t], total), do: h + sum(t, total)
  
  end
  </code></pre>
  
  <p>From my understanding this gets expanded by the compiler into:</p>
  
  <pre><code>defmodule Lists do
  
    def sum([]), do: sum([], 0)
    def sum([], total), do: total
    def sum([h|t], total), do: h + sum(t, total)
  
  end
  </code></pre>
  
  <p>So I would expect the following to happen: </p>
  
  <pre><code>iex(1)&gt; Lists.sum [1,2,3,4]
  ** (FunctionClauseError) no function clause matching in Lists.sum/1
  </code></pre>
  
  <p>instead it works:</p>
  
  <pre><code>iex(1)&gt; Lists.sum [1,2,3,4]
  10
  </code></pre>
  
  <p>Using <em>Elixir 0.12.4</em>.</p>