In erlang, I want to merge two list as the following
when, A = [1, 2, 3, 4], B= ["A1", "A2", "A3", A4],
wanted result [{1, "A1"}, {2, "A2"}, {3, "A3"}, {4, A4}]
I've tried the following
''' - module(test). - export([start/0]).
start() ->
Abc = [2,3,1,4],
Bbc=["f1", "f2", "f3",f4],
ct:pal("Hello ~n"),
ct:pal("make_tuple_list ~p~n", [make_tuple_list(Abc,Bbc)]).
make_tuple_list([H1 | T1], [H2 | T2]) ->
[_ | _] = [{H1, H2} | make_tuple_list(T1, T2)].
make_tuple_list([], []) -> [].
''' but got the systax erorr as the following
test.erl:14: function make_tuple_list/2 already defined
thanks in advance.
Try following....
Separator for splitting function clauses is
;..is function definition terminator. In the above case, both occurrences ofmake_tuple_listare ending with., which essentially means, in the second occurrence we are re-defining an already defined function, which is not allowed in ErLang.