[erlang-questions] Is this code tail recursive ?
Mihai Balea
mihai@REDACTED
Mon Feb 7 01:05:32 CET 2011
On Feb 6, 2011, at 6:08 PM, Radu Brumariu wrote:
> gather_files([]) -> [];
> gather_files(F) ->
> gather_files(F,[]).
> gather_files([],[Acc]) -> Acc;
> gather_files([{path,F}|Files],Acc) ->
> io:format("Processing path ~p~n",[F]),
> {ok, T} = file:read_file_info(F),
> case T#file_info.type
> of
> regular ->
> gather_files(Files, [F | Acc]);
> directory ->
> gather_files(Files, [gather_directory_files(F) | Acc ]);
> _ ->
> gather_files(Files, Acc)
> end.
>
> gather_directory_files(D) ->
> filelib:fold_files( D, ".*", true, fun(X,Acc) ->
> [X|Acc]
> end,
> []).
>
Looks tail recursive to me, although looking at the way you build up your result, it might not be what you expect :)
Not sure what you expect though, so I cannot comment on that.
Hope this helps,
Mihai
More information about the erlang-questions
mailing list