projog

3.118. msort(X,Y) - sorts a list.

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

Note that, unlike sort/2, duplicates are not removed.

Examples

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

yes

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

yes

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

yes

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

no

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

no

?- msort([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

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

yes

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

yes

?- msort(a, X).

no

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

no

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

yes

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

no

Note: unlike SWI Prolog, the following 3 queries will fail rather than cause an error.

?- msort(a, X).

no

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

no

?- msort([h,e,l,l,o|X], Y).

no