title: Finding all solutions in prolog
body: <p>In prolog I'm trying to unify every valid pairing of needs with resources</p>
  
  <pre><code>needs([ece2090,1,m,13,16]).
  needs([ece3520,1,tu,11,14]).
  needs([ece4420,1,w,13,16]).
  
  resources([joel, [ece2090,ece2010,ece3520,ece4420],[[m,13,16]]]).
  resources([sam, [ece2010,ece4420],[]]).
  resources([pete, [ece3520],[[w,13,16]]]).
  </code></pre>
  
  <p>using this formula</p>
  
  <pre><code>make_bid([Class,Sect,Day,Ts,Te],[Name,Cap,Unavail],[Class,Sect,Day,Ts,Te,Name,_]) :-
  no_conflict_all_unavailable(Day,Ts,Te,Unavail),
  course_capable(Class,Cap),
  writef('%w %w %w\n',[Class,Sect,Name]),
  fail.
  </code></pre>
  
  <p>and running this test.</p>
  
  <pre><code>test(Listing) :- needs(N), resources(R), make_bid(N,R,Listing).
  </code></pre>
  
  <p>The point of this part of the program is to pair every class with a teacher that both has the qualifications to teach the class and is not unavailable during that time. It's supposed to give a list.</p>
  
  <pre><code>?- test(Listing).
  ece3520 1 joel
  ece3520 1 pete
  ece4420 1 joel
  ece4420 1 sam
  false.
  </code></pre>
  
  <p>When run, the above is generated. This is correct, but it's in a format that's useless to me, since I need it to be a variable of its own to do further computations. Then the solution is to use bagof or findall, right?</p>
  
  <p>So I remove the fail clause from the main part of the program and then change the test to this    </p>
  
  <pre><code>test(Bag) :- needs(N), resources(R), bagof(Listing,make_bid(N,R,Listing),Bag).
  </code></pre>
  
  <p>but it generates this</p>
  
  <pre><code>ece3520 1 joel
  Bag = [[ece3520, 1, tu, 11, 14, joel, _G4310]] 
  </code></pre>
  
  <p>If you look closely you'll see that there's no period at the end as well as a lack of a true/false statement. This would lead one to believe it is infinitely looping. This isn't the case however, as the Bag matrix is fully formed and I can simply type "." to end the program (instead of, you know, aborting it).</p>
  
  <p>It only generates the first valid solution. Why is this happening?</p>