src/utilities.lisp, doc/misc.tex: Fix up `find-duplicates'.
[sod] / src / utilities.lisp
index 6e7a592..1670f55 100644 (file)
 ;;; along with SOD; if not, write to the Free Software Foundation,
 ;;; Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
-(cl:defpackage #:sod-utilities
-  (:use #:common-lisp
+(eval-when (:compile-toplevel :load-toplevel :execute)
+  (handler-bind ((warning #'muffle-warning))
+    (cl:defpackage #:sod-utilities
+      (:use #:common-lisp
 
-       ;; MOP from somewhere.
-       #+sbcl #:sb-mop
-       #+(or cmu clisp) #:mop
-       #+ecl #:clos))
+           ;; MOP from somewhere.
+           #+sbcl #:sb-mop
+           #+(or cmu clisp) #:mop
+           #+ecl #:clos))))
 
 (cl:in-package #:sod-utilities)
 
 ;;;--------------------------------------------------------------------------
+;;; Common symbols.
+;;;
+;;; Sometimes, logically independent packages will want to use the same
+;;; symbol, and these uses (by careful design) don't conflict with each
+;;; other.  If we export the symbols here, then the necessary sharing will
+;;; happen automatically.
+
+(export 'int)                          ; used by c-types and optparse
+
+;;;--------------------------------------------------------------------------
 ;;; Macro hacks.
 
 (export 'with-gensyms)
                              (setf (gethash k seen) item)))))
                sequence)))
        ((listp sequence)
-        (mapl (lambda (tail)
-                (let* ((item (car tail))
-                       (rest (cdr tail))
-                       (match (member (funcall key item) rest
-                                      :test test :key key)))
-                  (when match (funcall report item (car match)))))
-              sequence))
+        (do ((tail sequence (cdr tail))
+             (i 0 (1+ i)))
+            ((endp tail))
+            (let* ((item (car tail))
+                   (match (find (funcall key item) sequence
+                                :test test :key key :end i)))
+              (when match (funcall report item match)))))
        ((vectorp sequence)
         (dotimes (i (length sequence))
           (let* ((item (aref sequence i))
                  (pos (position (funcall key item) sequence
-                                :key key :test test :start (1+ i))))
+                                :key key :test test :end i)))
             (when pos (funcall report item (aref sequence pos))))))
        (t
         (error 'type-error :datum sequence :expected-type 'sequence))))