Question: Question 3 : ( 2 0 points for each case ) Write a predicate replacelast / 4 that substitutes the first argument x with the
Question : points for each case
Write a predicate replacelast that substitutes the first argument with the second argument for the last element, an occurrence of in a list of elements. If the list is empty the result is the empty list. If is not in the list, then the result is the list itself.
hint: the last occurrent is represented by when the tail is empty :
Three cases
The list is empty, then the result is empty
matches the head, insert in the new list and replace with
does not match the head and the tail is the empty list head, replace with in the tail
replacelastazabcarazR
replacelastazabcarayR
replacelast
replacelastazabcara R
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
