DEV Community

Discussion on: Understanding Recursion with Elixir

 
joshcheek profile image
Josh Cheek

Not sure I understand. Are you saying that all versions of the function have to have the same arity, so it needs a default value in order to have arity of 1 instead of zero?

My Elixir (1.7.4) didn't have any issue with it. Admittedly, you said it might be an Elixir 2 thing, but still, I'd expect arity to vary across signatures.

defmodule A do
  def b,      do: IO.puts "I am b"
  def b(arg), do: IO.puts "I am b(#{arg})"
end

A.b
A.b 123

Or maybe when you say "declare", it's like a C style declaration, where you're telling the compiler the signature so it can type map a call to a function signature before seeing the definition?