0
방금 Prolog로 작업하기 시작했으며 여러 술어로 작업하는 f}을 이해하지 못합니다. 예를 들어, 다음 문제를 해결해야합니다. 목록에서 다른 목록의 모든 요소로 값을 대체하십시오.여러 술어로 작업하는 Prolog
domains
elem=integer
list=elem*
predicates
%append to a list already created another list. There are 3 list parameters
%because I don't know other method
append (list,list,list)
%This will search the list (the first one) for the searched element and
%it is it will replace it with the list(the second one). The result will be
%kept in the third list.
add(list,list,elem,list)
goal
add([1,2,3,2,1],[4,5],2,L),
write (L).
clauses
add ([],[_],_,[]).
add ([A|L],L1,E,[A|L2]):-
add(L,L1,E,L2).
add ([E|L],L1,E,L2):-
add(L,L1,E,L2).
append([],[],L2).
append([],[X|L1],[X|L2]):-
append([],L1,L2).