title: Simple Prolog delete from list
body: <p>(This is NOT a coursework question. Just my own personal learning.)</p>
  
  <p>I'm trying to do an exercise in Prolog to delete elements from a list. Here's my code :</p>
  
  <pre><code>deleteall([],X,[]).
  deleteall([H|T],X,Result) :- 
      H==X,
      deleteall(T,X,Result).
  deleteall([H|T],X,[H|Result]) :- deleteall(T,X,Result).
  </code></pre>
  
  <p>When I test it, I first get a good answer (ie. with all the Xs removed.) But then the backtracking offers me all the other variants of the list with some or none of the instances of X removed.</p>
  
  <p>Why should this be? Why do cases where H==X ever fall through to the last clause?</p>