Question: Prolog Facts and Rules Example 2 In example2.pl, write a set of prolog facts and rules called mergeLists that merges (concatenates / appends) two lists.
Prolog Facts and Rules Example 2
In example2.pl, write a set of prolog facts and rules called mergeLists that merges (concatenates / appends) two lists. The given lists must be the first two arguments, and the merged list must be the third argument. Do not use the built in append rule.
Eg: mergeLists(List1, List2, Merged)
Your code should produce the following results:
?- mergeLists([7],[1,2,3], X).
X = [7,1,2,3].
?- mergeLists([2], [1], X).
X = [2, 1].
?- mergeLists([1], [], X).
X = [1].
example2.pl
%Definitions for isElementInList(El, List)
%Definitions for reverseList(List, ReversedList)
%insertElementIntoListEnd(El, List, NewList)
%Definitions for mergeLists(List1, List2, Merged)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
