title: Using PySwip to query Prolog database from python
body: <p>I have written a program in Prolog and I want to access its results in python. I had tried to write my code using pyDatalog but came across a problem I could not solve. Now I am trying PySwip because it lets me consult the database I had already created. </p>
  
  <p>Below is what my knowledge base looks like.</p>
  
  <pre><code>con('w1',a,c).
  con('w2',c,b).
  con('w3',b,d).
  con('w4',d,a).
  
  up('w1').
  up('w3').
  down('w2').
  down('w4').
  
  check(X,Y):-up(X),atom_concat('+', X, Y).
  
  check(X,Y):-down(X),atom_concat('-', X, Y).
  
  comb(Output,Input,A,B):- con(X,A,B), check(X,Y), append([Y],Input,Output).
  
  comb(Output,Input,A,B):- comb(Out,Input,A,C),con(X,C,B), check(X,Y), append([Y],Out,Output).
  </code></pre>
  
  <p>If I query <code>comb(O,[],a,b).</code> in SWI-Prolog, the result is <code>O = ['-w2', '+w1']</code></p>
  
  <p>Now in python I use PySwip to retrieve query results. As a test I ran the code below and got the result <code>a c</code> as expected.</p>
  
  <pre><code>from pyswip import Prolog
  prolog = Prolog()
  prolog.consult("knowledge_base.pl")
  for soln in prolog.query("con('w1',B,C)"):
      print(soln["B"],soln["C"])
  </code></pre>
  
  <p>However when  I ran the code below,</p>
  
  <pre><code>from pyswip import Prolog
  prolog = Prolog()
  prolog.consult("knowledge_base.pl")
  for soln in prolog.query("comb('O',[],a,b)"):
      print(soln["O"])
  </code></pre>
  
  <p>Nothing happens. Does anyone know why this doesn't work?</p>