Question

I did the following in order to get each list's head:

lists:map(fun hd/1, [[1, 2, 3], [4, 5, 6], [7, 8, 9]]).

The result is:

** exception error: undefined function erl_eval:hd/1

But when used otherwise:

lists:map(fun(A) -> hd(A) end, [[1, 2, 3], [4, 5, 6], [7, 8, 9]]).

I got appropriate result! Sorry for trivial question but can you tell me why it is not working with fun hd/1?

Était-ce utile?

La solution

Use fun erlang:hd/1 as the syntax. You need the module name here for that fun syntax to work.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top