From: Owen Rodley Date: Sun, 16 Jun 2013 01:26:45 +0000 (+1200) Subject: Use MACROLET for MAX and MIN X-Git-Url: http://repo.macrolet.net/gitweb/?a=commitdiff_plain;h=8b17fb21f80eb9028eecfe29e8d1b2a2613c7187;p=jscl.git Use MACROLET for MAX and MIN --- diff --git a/src/numbers.lisp b/src/numbers.lisp index 56328c8..dd09462 100644 --- a/src/numbers.lisp +++ b/src/numbers.lisp @@ -75,12 +75,14 @@ (defun evenp (x) (= (mod x 2) 0)) (defun oddp (x) (not (evenp x))) -(flet ((%max-min (x xs func) - (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 #'<))) +(macrolet ((def (name comparison) + `(defun ,name (x &rest xs) + (dolist (y xs) + (unless (,comparison x (car xs)) + (setq x y))) + x))) + (def max >) + (def min <)) (defun abs (x) (if (> x 0) x (- x)))