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

Jeroen Koops <>
Mon Mar 22 13:01:04 CET 2010


Really now? That goes to show, teaching =:= learning !

On Mon, Mar 22, 2010 at 12:57 PM, Bengt Kleberg
<>wrote:

> Greetings,
>
> You do not need to export the function to be able to use it in a
> fun func/arity
> expression.
>
>
> ebngt
>
> On Mon, 2010-03-22 at 12:53 +0100, Jeroen Koops 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 <
> >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 (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:
>
>


More information about the erlang-questions mailing list