title: Prolog: Checking if something is the last item in the list?
body: <p>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:</p>
  
  <pre><code>last(X,[Y|X]).
  last(X,[Y|Z]) :- last(X,Z).
  </code></pre>
  
  <p>I thought this would do the trick, but when I ask prolog:</p>
  
  <pre><code>?- last(c,[a,b,c]).
  </code></pre>
  
  <p>Prolog returns false. I tried the following query to see what Prolog thinks should fit my definition of last:</p>
  
  <pre><code>?- last(c,X).
  X = [_G530|c] ;
  X = [_G530, _G533|c] ;
  X = [_G530, _G533, _G536|c]
  </code></pre>
  
  <p>So, what I am not sure about is why the "|" symbol is still in the list?</p>
  
  <p>Update: last([c],[a,b,c]) produces the desired behavior. However, I'm not sure why my 1st argument has to be a list?</p>