title: Breadth First Search code won't output BFS result
body: <p>This is the code I found, and it was fixed in another <a href="https://stackoverflow.com/q/53236609/1243762">post</a> I made. </p>
  
  <pre><code>s(a, b).
  s(a, c).
  s(b, g).
  s(b, f).
  s(c, r).
  s(c, e).
  goal(g).
  
  solve( Start, Solution) :-
      breadthfirst( [ [Start] ], Solution).
  
  breadthfirst( [ [Node | Path] |_], [Node | Path] ) :-
      goal( Node).
  
  breadthfirst( [ [N | Path] | Paths], Solution) :-
      bagof([M,N|Path],
      ( s( N, M), \+ member( M, [N | Path] ) ), NewPaths),
      %conc( Paths, NewPaths, Pathsl), !,
      append(Paths, NewPaths, Pathsl), !,
      breadthfirst( Pathsl, Solution);
      breadthfirst( Paths, Solution).
  </code></pre>
  
  <p>However, I found that the output is :</p>
  
  <pre><code>?- solve(a,S).
  S = [g, b, a] ;
  </code></pre>
  
  <p>I took all the facts and draw a tree to represent them, and in the tree, we have <code>a</code> gives <code>b</code> and <code>c</code> which are at the same level, at level 1. Therefore they should be visited first. And then after, <code>g</code> will be visited in the 2nd level through <code>b</code>. </p>
  
  <p>So the output should be :</p>
  
  <pre><code>?- solve(a,S).
  S = [g, c, b, a] ;
  </code></pre>
  
  <p>But it isn't giving me that output and I don't know why.</p>
  
  <p>Now, there's also a problem of reversing the output, I would appreciate it if that is solved too. </p>