문제

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