passing a function to lists:map

Martin DeMello martindemello@REDACTED
Mon Mar 22 12:49:51 CET 2010


ta(X) when is_list(X)    -> list_to_atom(X);
ta(X) when is_tuple(X)   -> tuple_to_list(X);
ta(X) when is_integer(X) -> X.

% this doesn't work
atomize(List) -> lists:map(ta, List).

% this does
atomize(List) -> lists:map(fun(X) -> ta(X) end, List).

What's the difference? Have I just got the syntax wrong, or is there
some fundamental reason I need the second version?

martin


More information about the erlang-questions mailing list