;;; (cl:sort sequence less?)
;;; sorts a array, string, or list non-destructively. It does this
;;; by sorting a copy of the sequence. My understanding is that the
;;; Standard says that the result of append is always "newly
;;; allocated" except for sharing structure with "the last argument",
;;; so (append x '()) ought to be a standard way of copying a list x.
;@
(define (cl:sort seq less?)
(cond ((vector? seq)
(list->vector (cl:sort! (vector->list seq) less?)))
((string? seq)
(list->string (cl:sort! (string->list seq) less?)))
(else (cl:sort! (append seq '()) less?))))