Hello, I just started learning Elixir this week. I’m puzzled by an error I’m getting.
Here’s a simple module:
defmodule Mylist2 do
def reduce([], value, _func), do: value
def reduce([head | tail], value, func), do: reduce(tail, func.(head, value), func)
def max(a, b) when (a <= b), do: b
def max(a, b) when (a > b), do: a
def maxlist(list), do: reduce(list, -9999999, max)
end
When I compile the module I get this error:
** (CompileError) maxlist.exs:8: undefined function max/0 (expected Mylist2 to define such a function or for it to be imported, but none are available)
** (CompileError) compile error
(iex 1.13.4) lib/iex/helpers.ex:203: IEx.Helpers.c/2
It seems there’s something don’t know yet about how to reuse functions within a module … Someone can spot the problem?
The offending function seems to be the max function used in the reduce in the last line.
Many thanks!