I'm having a little trouble understanding list recursion and modification in Prolog. I'm trying to take a list of lists, then with each list, multiply each element in the list by the last element.
Here's a snippet of my code:
/*Find the last element of a list*/
lastelement(X,[X]).
lastelement(X,[_|L]) :- lastelement(X,L).
/*Multiply two lists together*/
multiplication(M1,M2,M1*M2).
/*Take a list, find the last element and multiply every part of that list by that element*/
/*Attach modified list to X*/
modifyL([],X) :- X is [].
modifyL([First|Tset],X) :- lastelement(Y,First),
multiplication(Y,First,MFirst),
modifyL([Tset],X),
append(X,MFirst,X).
When I try any list of lists, however, all I get is false. Can someone give me any pointers on list recursion that could help further understand this problem?