Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!mailrus!ames!ai.etl.army.mil!hoey From: hoey@ai.etl.army.mil (Dan Hoey) Newsgroups: comp.lang.lisp Subject: Re: what does "destructively sorted" mean in KCL? Message-ID: <320@ai.etl.army.mil> Date: 4 Aug 89 21:01:44 GMT References: <3916@phri.UUCP> <119605@sun.Eng.Sun.COM> Reply-To: hoey@ai.etl.army.mil (Dan Hoey) Organization: Naval Research Lab, Washington, DC Lines: 33 In article <119605@sun.Eng.Sun.COM> shiffman@sun.UUCP (Hank Shiffman) writes: >> >>>foo >>(1 3 9 4 -2 0 9) >> >>>(sort foo #'>) >>(9 9 4 3 1 0 -2) >> >>>foo >>(1 0 -2) ... >Keep in mind that since SORT is a function, (sort foo #'>) causes sort >to be handled the *value of FOO*, not the symbol itself. So SORT (as >it's currently defined) couldn't put sorted list back into FOO even if >it wanted to. Actually, you can make this work by using the cons cell you are given as the head of the list. For example, (defun my-sort (original &rest sortargs) (let ((sorted (apply #'sort original sortargs))) (unless (eq original sorted) (rotatef (car sorted) (car original)) (setf (cdr (do ((s sorted (cdr s))) ((eq (cdr s) original) s))) sorted) (rotatef (cdr original) (cdr sorted)))) original) doesn't CONS but does give its argument the value of the sorted list. This, however, requires that SORT return a list of which its argument is a tail, which is not explicitly required by CLtL. Dan