(declare (fixnum count))
(if (listp sequence)
(if from-end
- (nreverse (nlist-substitute*
- new old (nreverse (the list sequence))
- test test-not start end count key))
+ (let ((length (length sequence)))
+ (nreverse (nlist-substitute*
+ new old (nreverse (the list sequence))
+ test test-not (- length end) (- length start)
+ count key)))
(nlist-substitute* new old sequence
test test-not start end count key))
(if from-end
(declare (fixnum end count))
(if (listp sequence)
(if from-end
- (nreverse (nlist-substitute-if*
- new test (nreverse (the list sequence))
- start end count key))
+ (let ((length (length sequence)))
+ (nreverse (nlist-substitute-if*
+ new test (nreverse (the list sequence))
+ (- length end) (- length start) count key)))
(nlist-substitute-if* new test sequence
start end count key))
(if from-end
(declare (fixnum end count))
(if (listp sequence)
(if from-end
- (nreverse (nlist-substitute-if-not*
- new test (nreverse (the list sequence))
- start end count key))
+ (let ((length (length sequence)))
+ (nreverse (nlist-substitute-if-not*
+ new test (nreverse (the list sequence))
+ (- length end) (- length start) count key)))
(nlist-substitute-if-not* new test sequence
start end count key))
(if from-end
;;;; absolutely no warranty. See the COPYING and CREDITS files for
;;;; more information.
+;;; As reported by Paul Dietz from his ansi-test suite for gcl, REMOVE
+;;; malfunctioned when given :START, :END and :FROM-END arguments.
+;;; Make sure it doesn't happen again.
(let* ((orig '(1 2 3 2 6 1 2 4 1 3 2 7))
(x (copy-seq orig))
(y (remove 3 x :from-end t :start 1 :end 5))
(assert (equalp orig x))
(assert (equalp y '(1 2 2 6 1 2 4 1 3 2 7)))
(assert (equalp z '(1 3 6 1 2 4 1 3 2 7))))
+
+;;; Similarly, NSUBSTITUTE and friends were getting things wrong with
+;;; :START, :END and :FROM-END:
+(assert
+ (loop for i from 0 to 9 always
+ (loop for j from i to 10 always
+ (loop for c from 0 to (- j i) always
+ (let* ((orig '(a a a a a a a a a a))
+ (x (copy-seq orig))
+ (y (nsubstitute 'x 'a x :start i :end j :count c)))
+ (equal y (nconc (make-list i :initial-element 'a)
+ (make-list c :initial-element 'x)
+ (make-list (- 10 (+ i c))
+ :initial-element 'a))))))))
+
+(assert
+ (loop for i from 0 to 9 always
+ (loop for j from i to 10 always
+ (loop for c from 0 to (- j i) always
+ (let* ((orig '(a a a a a a a a a a))
+ (x (copy-seq orig))
+ (y (nsubstitute-if 'x (lambda (x) (eq x 'a)) x
+ :start i :end j
+ :count c :from-end t)))
+ (equal y (nconc (make-list (- j c) :initial-element 'a)
+ (make-list c :initial-element 'x)
+ (make-list (- 10 j)
+ :initial-element 'a))))))))
+(assert
+ (loop for i from 0 to 9 always
+ (loop for j from i to 10 always
+ (loop for c from 0 to (- j i) always
+ (let* ((orig '(a a a a a a a a a a))
+ (x (copy-seq orig))
+ (y (nsubstitute-if-not 'x (lambda (x)
+ (not (eq x 'a))) x
+ :start i :end j
+ :count c :from-end t)))
+ (equal y (nconc (make-list (- j c) :initial-element 'a)
+ (make-list c :initial-element 'x)
+ (make-list (- 10 j)
+ :initial-element 'a))))))))
+