J
Jimka
Guest
I thought of two really elegant ways of removing duplicate elements:
;; do it recursively
(defun uniqify (elements)
(cond ((memq (car elements) (cdr elements))
(uniqify (cdr elements)))
(elements
(cons (car elements) (uniqify (cdr elements))))))
;; and other elegant way that does not depend on a recursive function
(defun uniqify (elements)
(apply 'nconc
(foreach maplist sub elements
(unless (member (car sub) (cdr sub))
(list (car sub))))))
;; do it recursively
(defun uniqify (elements)
(cond ((memq (car elements) (cdr elements))
(uniqify (cdr elements)))
(elements
(cons (car elements) (uniqify (cdr elements))))))
;; and other elegant way that does not depend on a recursive function
(defun uniqify (elements)
(apply 'nconc
(foreach maplist sub elements
(unless (member (car sub) (cdr sub))
(list (car sub))))))