I have two unsorted lists, and I need to create another list that is sorted and where all the elements are unique.
Elements can occur several times in both lists, and they are initially unsorted.
My function looks like this:
(defun merge-lists (list-a list-b sort-fn) "Merges two lists of (x, y) coordinates sorting them and removing dupes" (let ((prev nil)) (remove-if (lambda (point) (let ((ret-val (equal point prev))) (setf prev point) ret-val)) (sort (merge 'list list-a list-b sort-fn) ;' sort-fn))))
Is there a better way to achieve the same?
Call example:
[CL]> (merge-lists '(9 8 4 8 9 7 2) '(1 7 3 9 2 6) #'>) ==> (9 8 7 6 4 3 2 1)
sorting list algorithm lisp
dsm
source share