[erlang-questions] passing a function to lists:map

Martin DeMello martindemello@REDACTED
Mon Mar 22 12:57:45 CET 2010


Thanks, Jeroen (and you too, Bob).

martin

On Mon, Mar 22, 2010 at 5:23 PM, Jeroen Koops <koops.j@REDACTED> wrote:
> Hi Martin,
> use:
> -export([ ta/1 ]).
> and then:
> atomize(List) -> lists:map(fun ta/1, List).
> Regards,
>
>
> On Mon, Mar 22, 2010 at 12:49 PM, Martin DeMello <martindemello@REDACTED>
> wrote:
>>
>> 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
>>
>> ________________________________________________________________
>> erlang-questions (at) erlang.org mailing list.
>> See http://www.erlang.org/faq.html
>> To unsubscribe; mailto:erlang-questions-unsubscribe@REDACTED
>>
>
>


More information about the erlang-questions mailing list