Извинения за отсутствие ясности в названии. Следующее - это очень специфический предикат, который я создаю, который работает частично только по назначению.
% replace_elements(+SearchingElementsList,+ReplacementsList,+OriginalList,-ResultingList).
% ResultingList consists of all elements of SearchingElementsList replaced by elements of ReplacementsList respectively.
replace_elements([],[],_,_).
replace_elements([H|T],[H2|T2],[H3|T3],List) :-
H \= H3, % H is not H3, therefore
replace_elements([H|T],[H2|T2],T3,List). % Skip this element and continue with T3.
replace_elements([H|T],[H2|T2],[H|T3],[H2|List]) :-
replace_elements(T,T2,T3,List). % H is found in OriginalList. Continue with tails.
В настоящее время
?- replace_elements([1,2,3],[one,two,three],[1,2,3,4,5],Result).
?- Result = [one,two,three|_7636].
Ожидаемое:
?- Result = [one,two,three,4,5].
Любой намек будет оценен!
Изменить: Применил рабочий ответ для моей конкретной проблемы.
% Eventually, recursion starts from all empty lists.
replace_elements([],[],[],[]).
% Rules are empty, push remaining H to List.
replace_elements([],[],[H|T],[H|List]) :-
replace_elements([],[],T,List).
% Empty list, just go through remaining rules.
replace_elements([H|T],[H2|T2],[],List) :-
replace_elements(T,T2,[],List).
% H < H3, move to next element in rules.
replace_elements([H|T],[H2|T2],[H3|T3],List) :-
H < H3,
replace_elements(T,T2,[H3|T3],List).
% H > H3, move to next element in original list.
replace_elements([H|T],[H2|T2],[H3|T3],[H3|List]) :-
H > H3,
replace_elements([H|T],[H2|T2],T3,List).
% Element is the same, push replacement H2 to List.
replace_elements([H|T],[H2|T2],[H|T3],[H2|List]) :-
replace_elements(T,T2,T3,List).