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.
#:map-combinations
#:map-derangements
#:map-permutations
- #:no-extremum
#:proper-sequence
#:random-elt
#:removef
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)))
(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)
(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)