stable-sort
(stable-sort sequence predicate &key key)
Sorts sequence like sort, but preserves the relative order of elements that predicate considers equal (neither (predicate a b) nor (predicate b a) is true). The optional :key function is applied to each element before comparison. A list, vector or string is sorted the same way sort sorts it: a list's cons cells are rearranged in place, and a vector or a non-literal string is sorted in its own storage and comes back as the same object (keeping a fill pointer and an adjustable flag, when present) -- a program-text string literal comes back as a fresh string instead. Use the return value rather than the original variable.