Skip to content

Instantly share code, notes, and snippets.

@x4lldux
Created October 8, 2015 16:37
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 x4lldux/7ec759a00af65612cd71 to your computer and use it in GitHub Desktop.
Save x4lldux/7ec759a00af65612cd71 to your computer and use it in GitHub Desktop.
Elixir function definition with default args
defmodule A do
def f(a \\ "a", b, c \\ "c", d \\ "d") do
IO.inspect a
IO.inspect b
IO.inspect c
IO.inspect d
IO.puts "####\n"
end
end
A.f "1"
A.f "1", "2"
A.f "1", "2", "3"
A.f "1", "2", "3", "4"
@x4lldux
Copy link
Author

x4lldux commented Oct 8, 2015

this will output:

"a"
"1"
"c"
"d"
####

"1"
"2"
"c"
"d"
####

"1"
"2"
"3"
"d"
####

"1"
"2"
"3"
"4"
####

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment