1.0.16.8: NCONC with dx &rest lists
[sbcl.git] / src / code / defboot.lisp
index dc5536e..16fd031 100644 (file)
@@ -69,7 +69,8 @@
 (defmacro-mundanely cond (&rest clauses)
   (if (endp clauses)
       nil
-      (let ((clause (first clauses)))
+      (let ((clause (first clauses))
+            (more (rest clauses)))
         (if (atom clause)
             (error "COND clause is not a list: ~S" clause)
             (let ((test (first clause))
                     `(let ((,n-result ,test))
                        (if ,n-result
                            ,n-result
-                           (cond ,@(rest clauses)))))
-                  `(if ,test
-                       (progn ,@forms)
-                       (cond ,@(rest clauses)))))))))
+                           (cond ,@more))))
+                  (if (eq t test)
+                      `(progn ,@forms)
+                      `(if ,test
+                           (progn ,@forms)
+                           ,(when more `(cond ,@more))))))))))
 
-;;; other things defined in terms of COND
 (defmacro-mundanely when (test &body forms)
   #!+sb-doc
   "If the first argument is true, the rest of the forms are
-  evaluated as a PROGN."
-  `(cond (,test nil ,@forms)))
+evaluated as a PROGN."
+  `(if ,test (progn ,@forms) nil))
+
 (defmacro-mundanely unless (test &body forms)
   #!+sb-doc
   "If the first argument is not true, the rest of the forms are
-  evaluated as a PROGN."
-  `(cond ((not ,test) nil ,@forms)))
+evaluated as a PROGN."
+  `(if ,test nil (progn ,@forms)))
+
 (defmacro-mundanely and (&rest forms)
   (cond ((endp forms) t)
         ((endp (rest forms)) (first forms))
          `(if ,(first forms)
               (and ,@(rest forms))
               nil))))
+
 (defmacro-mundanely or (&rest forms)
   (cond ((endp forms) nil)
         ((endp (rest forms)) (first forms))
     (style-warn "redefining ~S in DEFUN" name))
   (setf (sb!xc:fdefinition name) def)
 
+  (sb!c::note-name-defined name :function)
+
   ;; FIXME: I want to do this here (and fix bug 137), but until the
   ;; breathtaking CMU CL function name architecture is converted into
   ;; something sane, (1) doing so doesn't really fix the bug, and
 ;;; destructuring mechanisms.
 (defmacro-mundanely dotimes ((var count &optional (result nil)) &body body)
   (cond ((numberp count)
-         `(do ((,var 0 (1+ ,var)))
-              ((>= ,var ,count) ,result)
-            (declare (type unsigned-byte ,var))
-            ,@body))
-        (t (let ((v1 (gensym)))
-             `(do ((,var 0 (1+ ,var)) (,v1 ,count))
-                  ((>= ,var ,v1) ,result)
-                (declare (type unsigned-byte ,var))
-                ,@body)))))
+        `(do ((,var 0 (1+ ,var)))
+             ((>= ,var ,count) ,result)
+           (declare (type unsigned-byte ,var))
+           ,@body))
+        (t
+         (let ((c (gensym "COUNT")))
+           `(do ((,var 0 (1+ ,var))
+                 (,c ,count))
+                ((>= ,var ,c) ,result)
+              (declare (type unsigned-byte ,var)
+                       (type integer ,c))
+              ,@body)))))
 
 (defmacro-mundanely dolist ((var list &optional (result nil)) &body body)
   ;; We repeatedly bind the var instead of setting it so that we never