title: remove first occurrence of an element in Prolog
body: <p>I'm trying to remove the first occurrence of an element from a list in Prolog.</p>
  
  <p>My code:</p>
  
  <pre><code>remove_first_X(X,[X|Xs],Xs). %remove X
  remove_first_X(X,[Y|Xs],[Y|Xs]) :-
     remove_first_X(X,Xs,Xs).
  </code></pre>
  
  <p>Doesn't work:</p>
  
  <pre><code>?- remove_first_X(1,[1,2,3],[2,3]).
  true.
  
  ?- remove_first_X(1,[2,1,3],[2,3]).
  false.
  </code></pre>
  
  <p>Please help! :-)</p>
  
  <p>Another attempt is closer:</p>
  
  <pre><code>remove_first_X(X,[X|Xs],Xs).
  remove_first_X(X,[Y|Xs],[Y|Ys]) :-
     remove_first_X(X,Xs,Ys).
  </code></pre>
  
  <p>But removes X after its first occurrence:</p>
  
  <pre><code>?- remove_first_X(1,X,[2,1,0]).
  X = [1, 2, 1, 0] ;
  X = [2, 1, 1, 0] ;
  X = [2, 1, 1, 0] ;
  X = [2, 1, 0, 1] ;
  false.
  </code></pre>