Skip to content

Instantly share code, notes, and snippets.

@jc00ke
Created March 30, 2020 20:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jc00ke/7ef96c7088eb329ff6d72c8d7f440553 to your computer and use it in GitHub Desktop.
Save jc00ke/7ef96c7088eb329ff6d72c8d7f440553 to your computer and use it in GitHub Desktop.
defmodule Foo do
def bar(:a, opts \\ []), do: :a
def bar(:b, opts \\ []), do: :b
end
» iex
Erlang/OTP 22 [erts-10.6.4] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [hipe]
Interactive Elixir (1.10.2) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> c "foo.ex"
warning: variable "opts" is unused (if the variable is not meant to be used, prefix it with an underscore)
foo.ex:2: Foo.bar/2
warning: variable "opts" is unused (if the variable is not meant to be used, prefix it with an underscore)
foo.ex:3: Foo.bar/2
== Compilation error in file foo.ex ==
** (CompileError) foo.ex:3: def bar/2 defines defaults multiple times. Elixir allows defaults to be declared once per definition. Instead of:
def foo(:first_clause, b \\ :default) do ... end
def foo(:second_clause, b \\ :default) do ... end
one should write:
def foo(a, b \\ :default)
def foo(:first_clause, b) do ... end
def foo(:second_clause, b) do ... end
foo.ex:3: (module)
** (CompileError) compile error
(iex 1.10.2) lib/iex/helpers.ex:200: IEx.Helpers.c/2
iex(1)>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment