title: Prolog multiple predicates in findall/setof
body: <p>I'm trying to find ancestors of the Greek mythological Muses using the following facts and rules (simplified):</p>
  
  <pre><code>/* parent(A, B) - A is the parent of B */
  parent(zeus, calliope).
  parent(zeus, clio).
  parent(zeus, melpomene).
  parent(zeus, euterpe).
  parent(zeus, erato).
  parent(zeus, terpsichore).
  parent(zeus, urania).
  parent(zeus, thalia).
  parent(zeus, polymnia).
  parent(mnemosyne, calliope).
  parent(mnemosyne, clio).
  parent(mnemosyne, melpomene).
  parent(mnemosyne, euterpe).
  parent(mnemosyne, erato).
  parent(mnemosyne, terpsichore).
  parent(mnemosyne, urania).
  parent(mnemosyne, thalia).
  parent(mnemosyne, polymnia).
  
  parent(kronos, zeus).
  parent(rheia, zeus).
  parent(oranos, kronos).
  parent(gaia, oranos).
  </code></pre>
  
  <p>The <code>muse</code> and ancestor rules are defined as:</p>
  
  <pre><code>/* A is a Muse if A's parents are Zeus and Mnemosyne */
  muse(A):- parent(zeus, A), parent(mnemosyne, A).
  /* A is the ancestor of B if A is the parent of B */
  ancestor(A, B):- parent(A, B).
  /* A is an ancestor of C if A is the parent of B and B is the ancestor of C */
  ancestor(A, C):- parent(A, B), ancestor(B, C).
  </code></pre>
  
  <p>I want to essentially do the following:</p>
  
  <pre><code>/* Get the set of ancestors A of muses B and store in Z*/
  setof(A, ancestor(A, muse(B)), Z).
  </code></pre>
  
  <p>This doesn't work, and returns <code>false</code>. Another variant I tried:</p>
  
  <pre><code>findall(B, muse(B), Muses),
  setof(A, ancestor(A, Muses), Z).
  </code></pre>
  
  <p>But given that I have a lot more <code>parent</code> facts, it just iterates through every possible <code>ancestor</code> bag.</p>
  
  <p>The last variant I tried:</p>
  
  <pre><code>setof(A, ancestor(A, member(X, muse(X)), Z).
  </code></pre>
  
  <p>but that errors out with:</p>
  
  <pre><code>ERROR: Syntax error: Operator expected
  ERROR: setof(A, ancestor(A, member(X, muse(X)), Z)
  ERROR: ** here **
  ERROR: .
  </code></pre>
  
  <p>which makes sense.</p>
  
  <p>I want to be able to write the results, such as:</p>
  
  <pre><code>write('The Muses ancestors are: '), write(MuseAncestors), nl.
  </code></pre>
  
  <p>What am I doing wrong?</p>