So I have a program that has a predicate to replace the first occurrence of some element of a list with a given new element and produce a new list. I have it done like so:
changeFst(OldE,[OldE|T],NewE,[NewE|T]):-!.
changeFst(OldE,[_|T],NewE,_):- changeFst(OldE,T,NewE,_),!.
For example if you give (2,[1,2,3,4,2],10,X) it should give you back X=[1,10,3,4,2]
now im making the part that changes the last occurrence (in the example it would return X=[1,2,3,4,10]). Here's my code:
changeLast(OldE,OldL,NewE,NewL):-
reverse(OldE,X),
changeFst(OldE,X,NewE,NewL),
!.
so this works in fact perfectly but the thing is it returns me the list reversed ( in my upper example it returns me [10,4,3,2,1] instead of [1,2,3,4,10])
How can I just reverse this again to get my answer properly displayed?