diff options
-rw-r--r-- | stdlib.pl | 20 |
1 files changed, 20 insertions, 0 deletions
@@ -299,6 +299,10 @@ bagof_next_s([H|T], WT_list, Rest) :- ; Rest = Rest0 ). +setof(Template, Goal, Instances) :- + bagof(Template, Goal, Instances_list), + sort(Instances_list, Instances). + % misc helpers variable_set(Term, []) :- @@ -357,3 +361,19 @@ variant_list([], []). variant_list([H1|T1], [H2|T2]) :- variant(H1, H2), variant_list(T1, T2). + +% Sorting, which also removes duplicates (should be implemented in C for speed I think). + +sort(Ls0, Ls) :- + append(Lefts, [A,B|Rights], Ls0), + A @> B, + !, + append(Lefts, [B,A|Rights], Ls1), + sort(Ls1, Ls). +sort(Ls0, Ls) :- + append(Lefts, [A,B|Rights], Ls0), + A == B, + !, + append(Lefts, [A|Rights], Ls1), + sort(Ls1, Ls). +sort(Ls, Ls).
\ No newline at end of file |