[erlang-questions] Give me some advice

LUKE <>
Sun Feb 11 06:49:52 CET 2007


I am tring to do the excise about return a new tuple which is a copy of the tuple T 
where the Nth element of the tuple has been replaced by C.

Give me some advice on the following poor code. ie. tail recursion issue.....

-module(element).
-export([set2/3]).

set2(N,T,C)->list_to_tuple(set2(N,tuple_to_list(T),C,1)).

set2(_,[],_,_)->[];
set2(N,[H|T],C,Count)->
if 
N==Count ->[C|set2(N,T,C,Count+1)];
true->[H|set2(N,T,C,Count+1)]
end.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20070211/398f5e04/attachment.html>


More information about the erlang-questions mailing list