title: bagof/3 giving weird results
body: <p>I'm working in goal/prolog (prolog swi 6.0.0) and have a situation where I would like to do the following: I have the following things in my belief base:</p>
  
  <pre><code>elevator([agent0,0,[]])
  elevator([agent1,0,[]])
  elevator([agent2,0,[]])
  </code></pre>
  
  <p>then execute the following query: </p>
  
  <pre><code>if bel(bagof(Elevator,elevator(Elevator),Elevators)) then insert (elevatorList(Elevators)). 
  </code></pre>
  
  <p>However rather then the expected result of Elevators being </p>
  
  <pre><code>[[agent1,0,[]],[agent2,0,[]],[agent3,0,[]]]
  </code></pre>
  
  <p>the resulting list is </p>
  
  <pre><code>[Elevator/['.'(Agent0, '.'(0, '.'([], [])))]] [Elevator/['.'(Agent0, '.'(0, '.'([], []))),'.'(bidAgent, '.'(0, '.'([], [])))]] [Elevator/['.'(Agent0, '.'(0, '.'([], []))),'.'(bidAgent, '.'(0, '.'([], []))),'.'(agent1, '.'(0, '.'([], [])))]] 
  </code></pre>
  
  <p>Any idea what I'm doing wrong here?</p>