Use DOLIST instead of WHILE
authorOwen Rodley <Strigoides@gmail.com>
Sat, 18 May 2013 13:10:48 +0000 (01:10 +1200)
committerOwen Rodley <Strigoides@gmail.com>
Sun, 19 May 2013 23:06:26 +0000 (11:06 +1200)
src/numbers.lisp

index 24882b7..342c12d 100644 (file)
 ;; TODO: Use MACROLET when it exists
 (defmacro defcomparison (operator)
   `(defun ,operator (x &rest args)
-     (while (not (null args))
-       (if (,operator x (car args))
-         (setq x    (car args)
-               args (cdr args))
+     (dolist (y args) 
+       (if (,operator x y)
+         (setq x    (car args))
          (return-from ,operator nil)))
      t))
 
 (defun oddp  (x) (not (evenp x)))
 
 (flet ((%max-min (x xs func)
-         (while (not (null xs))
-           (setq x  (if (funcall func x (car xs))
-                      x
-                      (car xs))
-                 xs (cdr xs)))
+         (dolist (y xs) 
+           (setq x  (if (funcall func x (car xs)) x y)))
          x))
   (defun max (x &rest xs) (%max-min x xs #'>))
   (defun min (x &rest xs) (%max-min x xs #'<)))