[Small-cl-src] Haven't you always wanted to clean sequences out?
Pascal J.Bourguignon
pjb at informatimago.com
Fri Sep 3 21:27:19 UTC 2004
Ingvar writes:
> ;;; 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)))
(defun unique (data &key (test #'eql) (key #'identity))
(remove-duplicates data :test test :key key))
--
__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.
More information about the Small-cl-src
mailing list