The sort is done according to the standard ordering of terms. See compare/3 for this standard ordering. Note in particular that numbers are first ordered by their type (integer, float, etc) and only then by their magnitude, i.e. sorting numbers of different types may not give the expected result.
Note sort(L1,L2) is equivalent to sort(0,<,L1,L2). sort(L1,L2) differs from msort(L1,L2) in that it removes duplicates.
Success: sort([3,1,6,7,2],S). (gives S=[1,2,3,6,7]). sort([1,3,2,3,4,1],S). (gives S=[1,2,3,4]). sort([f(1,3),h(2,1)],S). (gives S=[f(1,3),h(2,1)]). sort(["b",2.0,a(1),1,a],S). (gives S=[2.0,1,"b",a,a(1)]). Fail: sort([2,1,3,4],[2,1,3,4]).