]> Repositorios git - scryer-prolog.git/commitdiff
use append/3 rather than set_difference/3 to gather witnesses in bagof/3 and setof...
authorMark Thom <[email protected]>
Tue, 13 Dec 2022 06:55:43 +0000 (23:55 -0700)
committerMark Thom <[email protected]>
Tue, 13 Dec 2022 06:55:55 +0000 (23:55 -0700)
src/lib/builtins.pl

index 1d2d0aed670b2fc2cf2cd9f5c65a0bcb22d7dfee..d73ff8dfb82a8ad9a065bc64e6b59cd54f480ff7 100644 (file)
@@ -745,11 +745,10 @@ findall_with_existential(Template, Goal, PairedSolutions, Witnesses0, Witnesses)
 
 bagof(Template, Goal, Solution) :-
     error:can_be(list, Solution),
-    term_variables(Template, TemplateVars0),
-    term_variables(Goal, GoalVars0),
-    sort(TemplateVars0, TemplateVars),
-    sort(GoalVars0, GoalVars),
-    set_difference(GoalVars, TemplateVars, Witnesses0),
+    term_variables(Template, TemplateVars),
+    term_variables(Goal, GoalVars),
+    term_variables(TemplateVars+GoalVars, TGVs),
+    lists:append(TemplateVars, Witnesses0, TGVs),
     findall_with_existential(Template, Goal, PairedSolutions0, Witnesses0, Witnesses),
     keysort(PairedSolutions0, PairedSolutions),
     group_by_variants(PairedSolutions, GroupedSolutions),
@@ -773,11 +772,10 @@ iterate_variants_and_sort([_|GroupSolutions], Ws, Solution) :-
 
 setof(Template, Goal, Solution) :-
     error:can_be(list, Solution),
-    term_variables(Template, TemplateVars0),
-    term_variables(Goal, GoalVars0),
-    sort(TemplateVars0, TemplateVars),
-    sort(GoalVars0, GoalVars),
-    set_difference(GoalVars, TemplateVars, Witnesses0),
+    term_variables(Template, TemplateVars),
+    term_variables(Goal, GoalVars),
+    term_variables(TemplateVars+GoalVars, TGVs),
+    lists:append(TemplateVars, Witnesses0, TGVs),
     findall_with_existential(Template, Goal, PairedSolutions0, Witnesses0, Witnesses),
     keysort(PairedSolutions0, PairedSolutions),
     group_by_variants(PairedSolutions, GroupedSolutions),