EricGT
July 17, 2022, 9:28pm
2
This is cross posted on StackOverflow
prolog, swi-prolog
Yes.
order_by/2
Here are some examples for order_by/2 from library(solution_sequences) as test cases .
:- begin_tests(order_by).
% run_tests(order_by).
data(0, 1, 1).
data(1, 0, 0).
data(0, 0, 0).
data(1, 1, 0).
data(1, 0, 1).
data(0, 0, 1).
data(1, 1, 1).
data(0, 1, 0).
% Bag ordering: same order as data
% Item output format: List
% Item element order: A,B,C
% Data source: facts
test(1,[ all( Cs == [[[0,1,1],[1,0,0],[0,0,0],[1,1,0],[1,0,1],[0,0,1],[1,1,1],[0,1,0]]] ) ] ) :-
bagof([A,B,C], data(A, B, C), Cs…
Note: order_by/2 will not work with your predicates because they have different names, i.e. p1
, p2
, …
They need to have the same functor for order_by/2 to work, e.g.
p( 201, 5, 2 ).
p( 301, 1, 2 ).
p( 401, 1, 4 ).
p( 501, 1, 5 ).
1 Like