[erlang-questions] lists:flatmap tail recursive?

Matthew Dempsky <>
Fri Apr 3 04:30:53 CEST 2009


2009/4/2 Yogish Baliga <>:
> Here is a code snippet from lists module.
>
> flatmap(F, [Hd|Tail]) ->
>     F(Hd) ++ flatmap(F, Tail);
> flatmap(F, []) when is_function(F, 1) -> [].
>
> I was wondering if it is tail recursive?

No, it's equivalent to

    flatmap(F, [Hd|Tail]) ->
        erlang:'++'(F(Hd), flatmap(F, Tail));
    flatmap(F, []) when is_function(F, 1) -> [].



More information about the erlang-questions mailing list