Re: Non-destructive sorts?



"robinganemccalla@xxxxxxxxx" <robinganemccalla@xxxxxxxxx> writes:

I want to know how (if it is possible) to have the following function
calls not alter the original values of my two lists

Of course. Copy the sequence first!


(defun sort-value (Entry1 Entry2)
(> (car Entry1) (car Entry2)))

(defun get-values (hand)
(mapcar #'cadr (stable-sort hand #'sort-value)))
(setq flist '((1 2) (3 4) (2 1)))
(setq glist '((5 8) (8 3)))
(setq tlist (append flist glist))
(get-values tlist)

when I do this, not only do I get different values for successive
calls, but the value of glist and flist change.


(defun get-values (hand)
(map 'list (function cadr)
(stable-sort (copy-seq hand) (function >) :key (function car))))


--
__Pascal Bourguignon__ http://www.informatimago.com/
Our enemies are innovative and resourceful, and so are we. They never
stop thinking about new ways to harm our country and our people, and
neither do we. -- Georges W. Bush
.



Relevant Pages

  • Re: Non-destructive sorts?
    ... (defun get-values (hand) ... your stable-sort function works? ... You should read up on parameter lists; ... sequence by comparing elements with the comparison function. ...
    (comp.lang.lisp)
  • Re: Non-destructive sorts?
    ... calls not alter the original values of my two lists ... (defun sort-value (Entry1 Entry2) ... (defun get-values (hand) ...
    (comp.lang.lisp)