anchor.diff:                   result-vector)))
               (t (error "~S is not a subtype of SEQUENCE." result-type))))))
   
  -(defun substitute-if (newitem predicate sequence &key key (start 0) end count) ; from-end
  +(defun substitute-if (newitem predicate sequence &key key (start 0) end count from-end)
     (check-type count (or null integer))
     (unless key (setf key 'identity))
     (cond ((and (listp sequence)
                 (zerop start)
  -              (null end))
  +              (null end)
  +              (not from-end))
            (mapcar (lambda (x)
                      (if (and (funcall predicate (funcall key x))
                               (or (null count)
  
positive.code:                  :key key
                   :start start
                   :end end
                   :count count))
  
  (defun nsubstitute-if (newitem predicate sequence &key key (start 0) end) ; from-end
    (unless key (setf key 'identity))
    (cond ((and (listp sequence)
                (zerop start)
                (null end))
           (mapcar (lambda (x)
                     (if (funcall predicate (funcall key x))
                         newitem
                         x))
                   sequence))
          (t (unless end (setf end (length sequence)))
             (dotimes (i (- end start))
               (when (funcall predicate (funcall key (elt sequence (+ start i))))
                 (setf (elt sequence (+ start i)) newitem)))
             sequence)))
  
  (defun nsubstitute-if-not (newitem predicate sequence &key key (start 0) end) ; from-end
    (unless key (setf key 'identity))
    (cond ((and (listp sequence)
                (zerop start)
                (null end))
           (mapcar (lambda (x)
                     (if (not (funcall predicate (funcall key x)))
                         newitem
                         x))
                   sequence))
          (t (unless end (setf end (length sequence)))
             (dotimes (i (- end start))
               (when (not (funcall predicate (funcall key (elt sequence (+ start i)))))
                 (setf (elt sequence (+ start i)) newitem)))
             sequence)))
  
  (defun nsubstitute (newitem olditem sequence &key test test-not key (start 0) end) ; from-end
    (check-test-test-not test test-not)
    (when test-not (setf test (complement test-not)))
    (unless test (setf test 'eql))
  
negative.code:                        newitem
                         x))
                   sequence))
          (t
           (unless end (setf end (length sequence)))
           (let ((new-sequence (if (listp sequence)
                                   (copy-list sequence)
                                   (make-array (length sequence)
                                               :element-type (array-element-type sequence)
                                               :initial-contents sequence))))
             (cond (from-end
                    (dotimes (i (- end start))
                      (when (and (funcall predicate (funcall key (elt new-sequence (- end i 1))))
                                 (or (null count)
                                     (>= (decf count) 0)))
                        (setf (elt new-sequence (- end i 1)) newitem)))
                    )
                   (t
                    (dotimes (i (- end start))
                      (when (and (funcall predicate (funcall key (elt new-sequence (+ start i))))
                                 (or (null count)
                                     (>= (decf count) 0)))
                        (setf (elt new-sequence (+ start i)) newitem)))))
             new-sequence))))
  
  (defun substitute-if-not (newitem predicate sequence &key key (start 0) end count from-end)
    (substitute-if newitem (complement predicate) sequence
                   :key key
                   :start start
                   :end end
                   :count count
                   :from-end from-end))
  
  (defun substitute (newitem olditem sequence &key test test-not key (start 0) end count from-end)
    (check-test-test-not test test-not)
    (when test-not (setf test (complement test-not)))
    (unless test (setf test 'eql))
  