projog

3.119. sort(X,Y) - sorts a list and removes duplicates.

Attempts to unify Y with a sorted version of the list represented by X, with duplicates removed.

Examples

?- sort([q,w,e,r,t,y], X).
X = [e,q,r,t,w,y]

yes

?- sort([q,w,e,r,t,y], [e,q,r,t,w,y]).

yes

?- sort([q,w,e,r,t,y], [q,w,e,r,t,y]).

no

?- sort([q,w,e,r,t,y], [e,q,t,r,w,y]).

no

?- sort([q,w,e,r,t,y], [A,B,C,D,E,F]).
A = e
B = q
C = r
D = t
E = w
F = y

yes

?- sort([], X).
X = []

yes

?- sort([a], X).
X = [a]

yes

?- sort(a, X).

no

?- sort([a,b,c|T], X).

no

?- sort([h,e,l,l,o], X).
X = [e,h,l,o]

yes

?- sort([h,e,l,l,o], [e,h,l,l,o]).

no