[alexandria.git] updated branch master: 0c39310 tweak EXTREMUM

Nikodemus Siivola nsiivola at common-lisp.net
Thu Apr 26 09:06:48 UTC 2012


The branch master has been updated:
       via  0c39310ebc2de5543157e6b862e909036b39d936 (commit)
      from  34488223ff5b7eb19d73075481c91f829af5d6bd (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 0c39310ebc2de5543157e6b862e909036b39d936
Author: Nikodemus Siivola <nikodemus at random-state.net>
Date:   Thu Apr 26 12:01:35 2012 +0300

    tweak EXTREMUM
    
     Return NIL if the sequence is empty, instead of the NO-EXTREMUM nonsense.
    
     It was bad design, because it's not an error someone higher up the stack can
     sensibly handle, and handling it locally is too verbose and slow.
    
        (or (extremum ...) (error ...))
    
     expresses the common case succintly, and fits the pattern of existing
     sequence functions.
    
     If it is deemed necessary, we can also add &KEY DEFAULT, but that seems
     overkill and has little precedent in sequence functions.

-----------------------------------------------------------------------

Summary of changes:
 package.lisp   |    1 -
 sequences.lisp |    5 ++---
 tests.lisp     |   10 +++-------
 3 files changed, 5 insertions(+), 11 deletions(-)

diff --git a/package.lisp b/package.lisp
index babeb95..cf258fc 100644
--- a/package.lisp
+++ b/package.lisp
@@ -114,7 +114,6 @@
    #:map-combinations
    #:map-derangements
    #:map-permutations
-   #:no-extremum
    #:proper-sequence
    #:random-elt
    #:removef
diff --git a/sequences.lisp b/sequences.lisp
index cb01081..8b9a443 100644
--- a/sequences.lisp
+++ b/sequences.lisp
@@ -506,8 +506,7 @@ The arguments to the PREDICATE function are computed from elements of SEQUENCE
 using the KEY function, if supplied. If KEY is not supplied or is NIL, the
 sequence element itself is used.
 
-If SEQUENCE is empty, then the error NO-EXTREMUM is signalled. Invoking the
-CONTINUE restart will cause extremum to return NIL."
+If SEQUENCE is empty, NIL is returned."
   (let* ((pred-fun (ensure-function predicate))
          (key-fun (unless (or (not key) (eq key 'identity) (eq key #'identity))
                     (ensure-function key)))
@@ -529,7 +528,7 @@ CONTINUE restart will cause extremum to return NIL."
                  (declare (dynamic-extent #'reduce-elts))
                  (reduce #'reduce-elts sequence :start start :end real-end))))
           ((= real-end start)
-           (cerror "Return NIL instead." 'no-extremum))
+           nil)
           (t
            (error "Invalid bounding indexes for sequence of length ~S: ~S ~S, ~S ~S"
                   (length sequence)
diff --git a/tests.lisp b/tests.lisp
index e218113..7ffe30f 100644
--- a/tests.lisp
+++ b/tests.lisp
@@ -1848,11 +1848,7 @@
         (incf n))
       (when (eql -1000 (extremum #(100 1 10 -1000) #'> :key 'abs))
         (incf n))
-      (let ((err nil))
-        (handler-bind ((no-extremum (lambda (c)
-                                      (setf err c)
-                                      (continue c))))
-          (when (eq nil (extremum "" #'error))
-            (when err
-              (incf n))))))
+      (when (eq nil (extremum "" (lambda (a b) (error "wtf? ~S, ~S" a b))))
+        (incf n))
+      n)
   13)
-- 
Alexandria hooks/post-receive




More information about the alexandria-cvs mailing list