Writing sort function, sort(A,B) in Prolog using the built in permutation Prolog function. The sort function holds if B is a sorted version of A.
% sorted holds if list is sorted
sorted([]).
sorted([A]).
sorted([A,B|T]) :- A=<B, sorted([B|T]).
% sort list holds if A is sorted list of B
sort(A,B) :- permutation(A,B), sorted(B).
The problem is: when there are duplicate values in L, R does not include these duplicates.
Output:
?- sort([1,4,2,5,4,4,2], X).
X = [1, 2, 4, 5].
How do I change the sort function so that it doesn't drop duplicates?