title: PROLOG Comparing 2 lists
body: <p>I've been trying for a long time and searched a lot (...) but nothing.</p>
  
  <p>What I want is to create a function that will compare elements of one list to the elements of other list.</p>
  
  <p>The things is I have absolutely no idea how I'm going to iterate through the members of both lists.</p>
  
  <p>Ex. comparing the first member of the first list L1 to the members of L2. If it meets a certain condition (the condition may vary, but compare/4, member and such won't do), I'll pick the second member of L1 to all the members of L2, and so on.</p>
  
  <p>The thing is I don't know how to get back the "full list" L2 after checking through its members while comparing to the first element of L1 by using [P|R]. After that how will I compare the second element of L1 to the elements of L2? Any way to "reset" it back to the first position?</p>
  
  <p>I had something like</p>
  
  <pre><code>function([P|R], [F|L]) :-
     P == F,
     function([P|R],L)
    ;
     P \== F, (guess not necessary)
     function(R, [F|L]).
  </code></pre>
  
  <p>(it has more stuff but this is pretty much the basic of what I want)</p>
  
  <p>But it exhibits odd behaviour after going through all the members of 1 list.</p>
  
  <p>And yes, it's probably a very basic question but Prolog is just not something I've gotten used to..</p>