I am new to prolog and am basically trying to write a clause that would evaluate as true if a given item is the last item in a given list. Here is what I have:
last(X,[Y|X]).
last(X,[Y|Z]) :- last(X,Z).
I thought this would do the trick, but when I ask prolog:
?- last(c,[a,b,c]).
Prolog returns false. I tried the following query to see what Prolog thinks should fit my definition of last:
?- last(c,X).
X = [_G530|c] ;
X = [_G530, _G533|c] ;
X = [_G530, _G533, _G536|c]
So, what I am not sure about is why the "|" symbol is still in the list?
Update: last([c],[a,b,c]) produces the desired behavior. However, I'm not sure why my 1st argument has to be a list?