title: Finding an intersection in Prolog using list predicates
body: <p>I'm really new to Prolog and I am trying to make an <code>isIntersection</code> that gives me the intersection of two lists and puts the answer in the third list. I cannot use any Prolog list predicates because it's for a class and that's just the rules. This is what I have and I'm having trouble debugging and seeing why this implementation is wrong. Anyone have any ideas?</p>
  
  <pre><code>/* Checks if the item is in the list */
  in(Item, [Item|Rest]).
  in(Item, [Not|Rest]) :- in(Item, Rest).
  
  /* Makes the intersection list */
  isIntersection([], [], []).
  isIntersection([H|R], List, [H|Final]) :-
     in(H, List),
     isIntersection(R, List, Final),
     write(H).
  isIntersection([Discard|Rest], List, Final) :-
     isIntersection(Rest, List, Final),
     write(Discard).
  </code></pre>