I got 2 warnings and “unexpected” behavior when trying to match argument as a list. Is this code incorrect? How can I match a argument as a List?
(It’s first code i am writing by myself I was trying to be close to the “book”)
I have following code
def choice(L) when is_list(L) do IO.puts("List") Enum.random(L) end def choice(a \\ -1, b \\ 1) do IO.puts("2 params") Enum.random([a,b]) end
Compiling warnings as following:
warning: this check/guard will always yield the same result
warning: incompatible types: L !~ [dynamic()] in expression: # NF.exs:2 is_list(L)
Results of executions are strange to me, it seems only last function is matched