title: Deleting all occurrences of an element from a list
body: <p>Trying to write a procedure that given a value and a list, it deletes all the occurence of that value in the list a wrote:</p>
  
  <pre><code>delMember(X, [], []) :- !.
  delMember(X, [X|Xs], Y) :- !, delMember(X, Xs, Y).
  delMember(X, [T|Xs], Y) :- !, delMember(X, Xs, Y2), append([T], Y2, Y).
  </code></pre>
  
  <p>Since the <code>cut</code> this code <strong>cannot</strong> answer correctly queries like:</p>
  
  <pre><code>delMember(Y, [1,2,3,1,2,3,1,2,3], [1, 2, 1, 2, 1, 2 ]).
  </code></pre>
  
  <p>If I delete the cuts:</p>
  
  <pre><code>delMember(X, [], []).
  delMember(X, [X|Xs], Y) :- delMember(X, Xs, Y).
  delMember(X, [T|Xs], Y) :- delMember(X, Xs, Y2), append([T], Y2, Y).
  </code></pre>
  
  <p>it fail in queries like:</p>
  
  <pre><code>delMember(Y, [1,2,3,1,2,3,1,2,3], [1,2,3,1,2,3,1,2,3]).
  </code></pre>
  
  <p>(returns <code>true</code> , when the correct answer is <code>false</code>).</p>
  
  <p>How can I make it works in both situations?</p>
  
  <p>Maybe I can check that <code>X is not T</code> in the third line of code, I tried:</p>
  
  <pre><code>delMember(X, [T|Xs], Y) :- not(X = T), delMember(X, Xs, Y2), append([T], Y2, Y).
  </code></pre>
  
  <p>but it does not work.</p>