oreillymedia / etudes-for-elixir

Companion exercises for Introducing Elixir
http://chimera.labs.oreilly.com/books/1234000001642
515 stars 159 forks source link

Etude 2-2 introduce default values and in Etude 3-1 they disappeared #38

Closed thilko closed 5 years ago

thilko commented 8 years ago

... if I continue to work with default values I am required to introduce a function head since I use claues with default values:

def area(:rectangle, length \\ 1, width \\ 1) do
    length * width
  end
   == Compilation error on file lib/geom.ex ==
   ** (CompileError) lib/geom.ex:15: def area/3 has default values and multiple clauses, define a function    head with the defaults
       lib/geom.ex:15: (module)
       (stdlib) erl_eval.erl:669: :erl_eval.do_apply/6

I have trouble with introducing the function head since this does not work:

def area(geom \\ :rectangle, length \\ 1, width \\ 1)