[Small-cl-src] Haven't you always wanted to clean sequences out?

Ingvar ingvar at cathouse.bofh.se
Fri Sep 3 19:04:10 UTC 2004


;;; Haven't we all felt the need to sanitize your sequences and making each
;;; element "unique"? I haven't, but I had some spare minutes waiting for
;;; a friend over lunch and since I'd been running the unix command uniq(1)
;;; and been irritated at its shortcomings, this came to be:

(defun unique (data &key (test #'eql) (key #'identity))
  (let ((acc nil)
	(type (typecase data (vector 'vector) (string 'string) (list 'list))))
    (flet ((frob (data)
		 (unless (member (funcall key data) acc :test test :key key)
		   (push data acc))))
      (map nil #'frob data))
    (coerce (nreverse acc) type)))






More information about the Small-cl-src mailing list