From: Ken Harris Date: Wed, 19 Jun 2013 18:44:44 +0000 (-0700) Subject: Fixed max/min functions. X-Git-Url: http://repo.macrolet.net/gitweb/?a=commitdiff_plain;h=50520b8f58d091bf2e033412b7e71b7846ea6aef;hp=57b5128b148076b44a9f207b59b6b7702b5fcad9;p=jscl.git Fixed max/min functions. --- diff --git a/src/numbers.lisp b/src/numbers.lisp index 3490df9..578d0b1 100644 --- a/src/numbers.lisp +++ b/src/numbers.lisp @@ -81,7 +81,7 @@ (macrolet ((def (name comparison) `(defun ,name (x &rest xs) (dolist (y xs) - (unless (,comparison x (car xs)) + (when (,comparison y x) (setq x y))) x))) (def max >) diff --git a/tests/numbers.lisp b/tests/numbers.lisp index 811d423..ae3ebb9 100644 --- a/tests/numbers.lisp +++ b/tests/numbers.lisp @@ -8,11 +8,13 @@ (test (= (max 1) 1)) (test (= (max 1 2 3) 3)) (test (= (max 3 2 1) 3)) +(test (= (max 1 2 3 4 5) 5)) ;;; MIN (test (= (min 1) 1)) (test (= (min 1 2 3) 1)) (test (= (min 3 2 1) 1)) +(test (= (min 9 3 8 7 6 3 3) 3)) ;;; EVENP (test (evenp 2))