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?

有帮助吗?

解决方案

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top