domains
x = integer
l = integer*
predicates
last(X,L)
list_add(l,x,l)
clauses
list_add([],X,[X]).
list_add([Y|List1],X,[Y|List2]) :-
list_add(List1,X,List2).
last(X,List) :-
list_add(List,X,List1),
write("The new list is ",List1),nl.
Output :
Goal: last(3,[3,6,1,5])
The new list is [3,6,1,5,3]
Yes