Question: Lists in PROLOG. Implement the following predicates in PROLOG: last/2, where the first parameter is a list and the second is the last element of
Lists in PROLOG. Implement the following predicates in PROLOG: last/2, where the first parameter is a list and the second is the last element of this list. For instance, the following fact should be provable: last([1, 2, 3], 3) reverse/2 with two argument lists in reverse element order. For instance, the following fact should be provable: reverse([1, 2, 3, 4], [4, 3, 2, 1]) chain/2 with two lists where the second is contained in the first as a consecutive partial list. For instance: chain([1, 2, 3, 4, 5, 6], [2, 3, 4]) remove/3 with one value and two lists as parameters. The second list is supposed to be identical to the first except for the removal of all occurrences of the first parameter. For instance: remove(2, [1, 2, 3, 2, 5], [1, 3, 5]) Hint: You may introduce auxiliary predicates.
1. Lists in PrOLOG. Implement the following predicates in PrOLOG: last/2, where the first parameter is a list and the second is the last element of this list. For instance, the following fact should be provable: last([1,2,3],3) * reverse/2 with two argument lists in reverse element order. For instance, the following fact should be provable: reverse([1,2,3,4], [4,3,2,1]) . chain/2 with two lists where the second is contained in the first as a con- secutive partial list. For instance: chain([1,2,3,4,5,6), [2,3,4]) * remove/3 with one value and two lists as parameters. The second list is supposed to be identical to the first except for the removal of all occurrences of the first parameter. For instance: remove(2, [1,2,3,2,5], [1,3,5]) Hint: You may introduce auxiliary predicates. 1. Lists in PrOLOG. Implement the following predicates in PrOLOG: last/2, where the first parameter is a list and the second is the last element of this list. For instance, the following fact should be provable: last([1,2,3],3) * reverse/2 with two argument lists in reverse element order. For instance, the following fact should be provable: reverse([1,2,3,4], [4,3,2,1]) . chain/2 with two lists where the second is contained in the first as a con- secutive partial list. For instance: chain([1,2,3,4,5,6), [2,3,4]) * remove/3 with one value and two lists as parameters. The second list is supposed to be identical to the first except for the removal of all occurrences of the first parameter. For instance: remove(2, [1,2,3,2,5], [1,3,5]) Hint: You may introduce auxiliary predicates
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
