From: Paul.Broome <Paul.Broome@MDLogix.com> - 2005-01-22 21:05:33
|
Bart and Kostis, Thank you for your help. Also, syslib/setof.H will need a clause to import variant/2. In my program, the new version gives the same solution as sicstus, ciao, and swi - that is, it backtracks for the case where the two eq's collapse. I'm now puzzled over why it backtracks and have been working to return all these answers in one list. Maybe there's something else I can read to better understand. I'm grateful again. paul Kostis Sagonas wrote: >Bart Demoen wrote: > > ... [snip] ... > > > > The problem is in pick/3 in setof.P - indeed the parade/3 does this > > unification where it should have been == testing, but pick should > > first start with doing some unifications in the key part: > > the first argument of pick (for the example) is something like > > > > ... [snip] ... > >Although no doubt Bart's suggestion for fixing the problem is most >probably correct, I admit I do not understand it (in particular I do >not see how to solve the problem using unification in the key part, >but no doubt there is one), so I wrote my own fix to it. > >The following code works OK for Bart's examples, fixes Paul's original >bug report and seems to work for all other of my tests. If you think >it is OK, include it in XSB (it is just a matter of substituting the >same predicates in setof.P and adding the necessary import declaration >to setof.H). > >------------------------------------------------------------------------ >pick([K-X|Bags], Key, Bag) :- > parade(Bags, K, Bag1, Bags1), > decide(Bags1, [X|Bag1], K, Key, Bag). > >parade([K-X|L1], Key, Bag1, L) :- > variant(K, Key), > !, > Bag1 = [X|B1], > parade(L1, Key, B1, L). >parade(L, _, [], L). > >decide([], Bag, Key, Key, Bag) :- !. >decide(_, Bag, Key, Key, Bag). >decide(Bags, _, _, Key, Bag) :- pick(Bags, Key, Bag). >------------------------------------------------------------------------ > >Hope this helps. > >Cheers, >Kostis. > > > > |