0.pre7.36
[sbcl.git] / src / code / list.lisp
index 13244d3..4f78953 100644 (file)
@@ -11,9 +11,6 @@
 
 (in-package "SB!IMPL")
 
-(file-comment
-  "$Header$")
-
 ;;;; KLUDGE: comment from CMU CL, what does it mean?
 ;;;;   NSUBLIS, things at the beginning broken.
 ;;;; -- WHN 20000127
 (defun complement (function)
   #!+sb-doc
   "Builds a new function that returns T whenever FUNCTION returns NIL and
-   NIL whenever FUNCTION returns T."
-  #'(lambda (&optional (arg0 nil arg0-p) (arg1 nil arg1-p) (arg2 nil arg2-p)
-                      &rest more-args)
-      (not (cond (more-args (apply function arg0 arg1 arg2 more-args))
-                (arg2-p (funcall function arg0 arg1 arg2))
-                (arg1-p (funcall function arg0 arg1))
-                (arg0-p (funcall function arg0))
-                (t (funcall function))))))
-
-(defun constantly (value &optional (val1 nil val1-p) (val2 nil val2-p)
-                        &rest more-values)
-  #!+sb-doc
-  "Builds a function that always returns VALUE, and posisbly MORE-VALUES."
-  (cond (more-values
-        (let ((list (list* value val1 val2 more-values)))
-          #'(lambda ()
-              (declare (optimize-interface (speed 3) (safety 0)))
-              (values-list list))))
-       (val2-p
-        #'(lambda ()
-            (declare (optimize-interface (speed 3) (safety 0)))
-            (values value val1 val2)))
-       (val1-p
-        #'(lambda ()
-            (declare (optimize-interface (speed 3) (safety 0)))
-            (values value val1)))
-       (t
-        #'(lambda ()
-            (declare (optimize-interface (speed 3) (safety 0)))
-            value))))
+   NIL whenever FUNCTION returns non-NIL."
+  (lambda (&optional (arg0 nil arg0-p) (arg1 nil arg1-p) (arg2 nil arg2-p)
+                    &rest more-args)
+    (not (cond (more-args (apply function arg0 arg1 arg2 more-args))
+              (arg2-p (funcall function arg0 arg1 arg2))
+              (arg1-p (funcall function arg0 arg1))
+              (arg0-p (funcall function arg0))
+              (t (funcall function))))))
+
+(defun constantly (value)
+  #!+sb-doc
+  "Return a function that always returns VALUE."
+  (lambda ()
+    ;; KLUDGE: This declaration is a hack to make the closure ignore
+    ;; all its arguments without consing a &REST list or anything.
+    ;; Perhaps once DYNAMIC-EXTENT is implemented we won't need to
+    ;; screw around with this kind of thing. -- WHN 2001-04-06
+    (declare (optimize (speed 3) (safety 0)))
+    value))
 \f
 ;;;; macros for (&KEY (KEY #'IDENTITY) (TEST #'EQL TESTP) (TEST-NOT NIL NOTP))
 
-;;; Use these with the following keyword args:
+;;; Use these with the following &KEY args:
 (defmacro with-set-keys (funcall)
-  `(cond ((and testp notp) (error "Test and test-not both supplied."))
+  `(cond ((and testp notp) (error ":TEST and :TEST-NOT were both supplied."))
         (notp ,(append funcall '(:key key :test-not test-not)))
         (t ,(append funcall '(:key key :test test)))))
 
 (defun member (item list &key key (test #'eql testp) (test-not nil notp))
   #!+sb-doc
   "Returns tail of list beginning with first element satisfying EQLity,
-   :test, or :test-not with a given item."
+   :TEST, or :TEST-NOT with a given item."
   (do ((list list (cdr list)))
       ((null list) nil)
     (let ((car (car list)))
 
 (defun member-if (test list &key key)
   #!+sb-doc
-  "Returns tail of list beginning with first element satisfying test(element)"
+  "Return tail of LIST beginning with first element satisfying TEST."
   (do ((list list (Cdr list)))
       ((endp list) nil)
     (if (funcall test (apply-key key (car list)))
 
 (defun member-if-not (test list &key key)
   #!+sb-doc
-  "Returns tail of list beginning with first element not satisfying test(el)"
+  "Return tail of LIST beginning with first element not satisfying TEST."
   (do ((list list (cdr list)))
       ((endp list) ())
     (if (not (funcall test (apply-key key (car list))))
 
 (defun tailp (object list)
   #!+sb-doc
-  "Returns true if Object is the same as some tail of List, otherwise
-   returns false. List must be a proper list or a dotted list."
+  "Return true if OBJECT is the same as some tail of LIST, otherwise
+   returns false. LIST must be a proper list or a dotted list."
   (do ((list list (cdr list)))
       ((atom list) (eql list object))
     (if (eql object list)
 
 (defun adjoin (item list &key key (test #'eql) (test-not nil notp))
   #!+sb-doc
-  "Add item to list unless it is already a member"
+  "Add ITEM to LIST unless it is already a member"
   (declare (inline member))
   (if (let ((key-val (apply-key key item)))
        (if notp
 ;;; order.
 (defun union (list1 list2 &key key (test #'eql testp) (test-not nil notp))
   #!+sb-doc
-  "Returns the union of list1 and list2."
+  "Return the union of LIST1 and LIST2."
   (declare (inline member))
   (when (and testp notp) (error "Test and test-not both supplied."))
   (let ((res list2))
        (push elt res)))
     res))
 
-;;; Destination and source are setf-able and many-evaluable. Sets the source
-;;; to the cdr, and "conses" the 1st elt of source to destination.
+;;; Destination and source are SETF-able and many-evaluable. Set the
+;;; SOURCE to the CDR, and "cons" the 1st elt of source to DESTINATION.
 ;;;
 ;;; FIXME: needs a more mnemonic name
 (defmacro steve-splice (source destination)
 
 (defun nunion (list1 list2 &key key (test #'eql testp) (test-not nil notp))
   #!+sb-doc
-  "Destructively returns the union list1 and list2."
+  "Destructively return the union of LIST1 and LIST2."
   (declare (inline member))
   (if (and testp notp)
-      (error "Test and test-not both supplied."))
+      (error ":TEST and :TEST-NOT were both supplied."))
   (let ((res list2)
        (list1 list1))
     (do ()
 (defun intersection (list1 list2 &key key
                           (test #'eql testp) (test-not nil notp))
   #!+sb-doc
-  "Returns the intersection of list1 and list2."
+  "Return the intersection of LIST1 and LIST2."
   (declare (inline member))
   (if (and testp notp)
       (error "Test and test-not both supplied."))
 (defun nintersection (list1 list2 &key key
                            (test #'eql testp) (test-not nil notp))
   #!+sb-doc
-  "Destructively returns the intersection of list1 and list2."
+  "Destructively return the intersection of LIST1 and LIST2."
   (declare (inline member))
   (if (and testp notp)
       (error "Test and test-not both supplied."))
 (defun set-difference (list1 list2 &key key
                             (test #'eql testp) (test-not nil notp))
   #!+sb-doc
-  "Returns the elements of list1 which are not in list2."
+  "Return the elements of LIST1 which are not in LIST2."
   (declare (inline member))
   (if (and testp notp)
       (error "Test and test-not both supplied."))
 (defun nset-difference (list1 list2 &key key
                              (test #'eql testp) (test-not nil notp))
   #!+sb-doc
-  "Destructively returns the elements of list1 which are not in list2."
+  "Destructively return the elements of LIST1 which are not in LIST2."
   (declare (inline member))
   (if (and testp notp)
       (error "Test and test-not both supplied."))
 (defun set-exclusive-or (list1 list2 &key key
                               (test #'eql testp) (test-not nil notp))
   #!+sb-doc
-  "Returns new list of elements appearing exactly once in list1 and list2."
+  "Return new list of elements appearing exactly once in LIST1 and LIST2."
   (declare (inline member))
   (let ((result nil))
     (dolist (elt list1)
        (setq result (cons elt result))))
     result))
 
-;;; The outer loop examines list1 while the inner loop examines list2. If an
-;;; element is found in list2 "equal" to the element in list1, both are
-;;; spliced out. When the end of list1 is reached, what is left of list2 is
-;;; tacked onto what is left of list1. The splicing operation ensures that
-;;; the correct operation is performed depending on whether splice is at the
-;;; top of the list or not
-
+;;; The outer loop examines list1 while the inner loop examines list2.
+;;; If an element is found in list2 "equal" to the element in list1,
+;;; both are spliced out. When the end of list1 is reached, what is
+;;; left of list2 is tacked onto what is left of list1. The splicing
+;;; operation ensures that the correct operation is performed
+;;; depending on whether splice is at the top of the list or not
 (defun nset-exclusive-or (list1 list2 &key (test #'eql) (test-not nil notp)
                                key)
   #!+sb-doc
-  "Destructively return a list with elements which appear but once in list1
-   and list2."
+  "Destructively return a list with elements which appear but once in LIST1
+   and LIST2."
   (do ((list1 list1)
        (list2 list2)
        (x list1 (cdr x))
 
 (defun subsetp (list1 list2 &key key (test #'eql testp) (test-not nil notp))
   #!+sb-doc
-  "Returns T if every element in list1 is also in list2."
+  "Return T if every element in LIST1 is also in LIST2."
   (declare (inline member))
   (dolist (elt list1)
     (unless (with-set-keys (member (apply-key key elt) list2))
 
 (defun acons (key datum alist)
   #!+sb-doc
-  "Construct a new alist by adding the pair (key . datum) to alist"
+  "Construct a new alist by adding the pair (KEY . DATUM) to ALIST."
   (cons (cons key datum) alist))
 
 (defun pairlis (keys data &optional (alist '()))
   #!+sb-doc
-  "Construct an association list from keys and data (adding to alist)"
+  "Construct an association list from KEYS and DATA (adding to ALIST)."
   (do ((x keys (cdr x))
        (y data (cdr y)))
       ((and (endp x) (endp y)) alist)