My code merges two lists of lists, item by item, in the following way:
mergeL([[a,b],[c,d]], [[1,2],[3,4]], Result). Result = [[a,b,1,2],[c,d,3,4]]
And this is the code i use:
mergeL([],[],[]).
mergeL(List, [], List).
mergeL([], List, List).
mergeL([X|Rest],[Y|Rest2], [XY|Res2]) :- mergeL(Rest, Rest2, Res2), append(X,Y,XY).
This seems to work but if i call it with two lists of the same size i get three repeated results. Example (both list contain only one element):
?- mergeL([[a,b]],[[1,2,3]],Q).
Q = [[a, b, 1, 2, 3]] ;
Q = [[a, b, 1, 2, 3]] ;
Q = [[a, b, 1, 2, 3]].
Is there a clean way to make this output only one solution?