To add to what Paweł Obrok said, the reason this returns BadArityError
is because print.()
calls your print
function with no arguments, but it expects a tuple as its argument.
That's actually masking the real problem - that you're calling the function instead of passing it as an argument. If you pass the print.()
function call a tuple, thus resolving the BadArityError
, you get the real error:
Enum.__info__(:functions) |> Enum.each(print.({:foo, :bar}))
foo/bar
** (BadFunctionError) expected a function, got: :ok
(elixir) lib/enum.ex:769: Enum."-each/2-lists^foreach/1-0-"/2
(elixir) lib/enum.ex:769: Enum.each/2
The print
function is executed, performing the IO.puts "#{function}/#{arity}"
as you can see from the foo/bar
output, then returns the result of IO.puts/1
, which is:ok
, and passes that as the second argument to Enum.each
. That causes BadFunctionError
because Enum.each
expects a function as its second argument, but you gave the result of executing the function - the atom :ok
.