Update of /project/cl-utilities/cvsroot/cl-utilities In directory common-lisp.net:/tmp/cvs-serv3996
Modified Files: extremum.lisp Log Message: Updated and improved documentation
Date: Thu May 26 21:20:28 2005 Author: pscott
Index: cl-utilities/extremum.lisp diff -u cl-utilities/extremum.lisp:1.5 cl-utilities/extremum.lisp:1.6 --- cl-utilities/extremum.lisp:1.5 Tue May 17 21:17:34 2005 +++ cl-utilities/extremum.lisp Thu May 26 21:20:28 2005 @@ -22,6 +22,11 @@ (if (funcall ,test a b) a b)) whole))
+;; The normal way of testing the if length of a proper sequence equals +;; zero is to just use (zerop (length sequence)). And, while some +;; implementations may optimize this, it's probably a good idea to +;; just write an optimized version and use it. This method can speed +;; up list length testing. (defun zero-length-p (sequence) "Is the length of SEQUENCE equal to zero?" (declare (optimize (speed 3) (safety 0) (space 0) (debug 1))) @@ -51,9 +56,7 @@ &key (key #'identity) (start 0) end) "Returns the element of SEQUENCE that would appear first if the sequence were ordered according to SORT using PREDICATE and KEY. See -http://www.cliki.net/EXTREMUM for the full -specification. Additionally, START and END specify the beginning and -ending indices of the part of the sequence we should look at." +http://www.cliki.net/EXTREMUM for the full specification." (with-check-length (sequence start end) (reduce (comparator predicate key) sequence :start start :end end))) @@ -68,15 +71,6 @@ (reduce (comparator ,predicate) ,sequence :start ,start :end ,end)))) whole)) - -;; And, for backup, here's a strictly spec-compliant version. -#+nil -(defun extremum (sequence predicate &key (key #'identity)) - "Returns the element of SEQUENCE that would appear first if the -sequence were ordered according to SORT using PREDICATE and KEY. See -http://www.cliki.net/EXTREMUM for the full specification." - (with-check-length (sequence 0 nil) - (reduce (comparator predicate key) sequence)))
;; This is an "optimized" version which calls KEY less. REDUCE is ;; already so optimized that this will actually be slower unless KEY