Loop and Maplist in Prolog
Here maplist iterates on all elements of more than one lists one by one and performs any specified operation and save the resultant in third List
Example : operation of sumList being performed on L,L2 lists and resultant is saved into Result named List.
sumList([],[],[]).
sumList(A,B,C) :-
C is A+B.
printList([]).
printList([H|T]) :-
write(H),
printList(T).
sum_list :-
L=[1,2,3],
L2=[1,2,3],
maplist(sumList,L,L2,Result),
printList(Result).
0 Comments:
Post a Comment