[erlang-questions] list:join() for erlang?

David Mercer dmercer@REDACTED
Thu Sep 13 21:45:45 CEST 2007


On Thursday, September 13, 2007, Ben Munat wrote:
> Out of curiosity -- still feeling my way around erlang and functional 
> programming -- aren't the "helper" functions here stack-recursive (i.e.
*not* 
> tail-recursive)?

Looks like you're right.  Here's my tail-recursive version of the same:

	join([], _) -> [];
	join([S1 | S_Rest], Sep) ->
		S1 ++ reverse_join(lists:reverse(S_Rest), Sep, []).

	reverse_join([], _, Joined) -> Joined;
	reverse_join([S1 | S_Rest], Sep, Joined) ->
		reverse_join(S_Rest, Sep, Sep ++ S1 ++ Joined).

Cheers,

David




More information about the erlang-questions mailing list