Commit 0c39310e authored by Nikodemus Siivola's avatar Nikodemus Siivola
Browse files


 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.
parent 34488223
......@@ -114,7 +114,6 @@
......@@ -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))
(error "Invalid bounding indexes for sequence of length ~S: ~S ~S, ~S ~S"
(length sequence)
......@@ -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))
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment