Hi All! I’m trying to use predsort/3 to sort a list and remove variant duplicates. The code si like this:
order_variants(=, A, B) :-
A =@= B.
order_variants(Order, A, B) :-
A \=@= B, % i know, that this is not optimal
compare(Order, A, B).
sorted_sorted(Sorted_1, Sorted_2) :-
List_1 = [
key(A)-value(A),
key(B)-different_value(B),
key(C)-value(C)
],
List_2 = [
key(P)-value(P),
key(Q)-value(Q),
key(R)-different_value(R)
],
predsort(order_variants, List_1, Sorted_1),
predsort(order_variants, List_2, Sorted_2).
Even though the List_1 and List_2 should be (variantly) the same, only with changed order of the elements, predsort/3 does not remove the duplicate key()-value() in the Sorted_1, but does it in the Sorted_2.
sorted_sorted(Sorted_1 ,Sorted_2).
Sorted_1 = [key(_19434)-value(_19434), key(_19454)-different_value(_19454), key(_19474)-value(_19474)],
Sorted_2 = [key(_19494)-value(_19494), key(_19534)-different_value(_19534)].
All the other checks confirm, that those two elements are considered as variants and there are no other solutions:
?- order_variants(Order, key(A)-value(A), key(C)-value(C)).
Order = (=) ;
false.
?- key(A)-value(A) =@= key(C)-value(C).
true.
Could somebody please explain why? Thanks.