[erlang-questions] about tail-recursive

成立涛 <>
Wed Apr 16 10:57:23 CEST 2008


Hi everyone.
Recently I read http://www.erlang.org/download/armstrong_thesis_2003.pdf.
 In this paper 3.3.8, the author talk about tail-recursive:
"Firstly the non tail-recursive way:
factorial(0) -> 1;
factorial(N) -> N * factorial(N-1).
"
I see this section is non tail-recursive. In my mind, the tail-recursive is
the better, because it do not consuming stack!

When I read OTP src, I find in the stdlib lists.erl. the map/2 write in this
style:
"map(F, [H|T]) ->
    [F(H)|map(F, T)];
map(F, []) when is_function(F, 1) -> [].
"
I think it's non tail-recursive? realy? and why not ?
tanks !
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20080416/5a4e81f3/attachment.html>


More information about the erlang-questions mailing list