From: Owen Rodley Date: Fri, 10 May 2013 01:02:04 +0000 (+1200) Subject: Misc. fixes to SUBSEQ, tests X-Git-Url: http://repo.macrolet.net/gitweb/?a=commitdiff_plain;h=e81a6b71ed71610ef3134dde23487f2d0a762b7b;p=jscl.git Misc. fixes to SUBSEQ, tests --- diff --git a/src/sequence.lisp b/src/sequence.lisp index 7b8fa4e..8d2701b 100644 --- a/src/sequence.lisp +++ b/src/sequence.lisp @@ -133,15 +133,15 @@ ((minusp diff) (error "Start index must be smaller than end index")) (t - (let* ((drop-a (nthcdr a seq)) + (let* ((drop-a (copy-list (nthcdr a seq))) (pointer drop-a)) - (dotimes (n (1- diff)) + (dotimes (_ (1- diff)) (setq pointer (cdr pointer)) (when (null pointer) (error "Ending index larger than length of list"))) - (setf (cdr pointer) nil) + (rplacd pointer ()) drop-a)))) - (nthcdr a seq))) + (copy-list (nthcdr a seq)))) ((arrayp seq) (if b (slice seq a b) diff --git a/tests/seq.lisp b/tests/seq.lisp index c117831..1f2ffc2 100644 --- a/tests/seq.lisp +++ b/tests/seq.lisp @@ -13,3 +13,9 @@ (let ((v1 (remove-if #'zerop #(1 0 2 0 3)))) (test (and (= (aref v1 0) 1) (= (aref v1 1) 2) (= (aref v1 2) 3)))) (test (every #'zerop (remove-if-not #'zerop #(1 0 2 0 3)))) + +(let ((nums '(1 2 3 4 5))) + (test (equal (subseq nums 3) '(4 5))) + (test (equal (subseq nums 2 4) '(3 4))) + ; Test that nums hasn't been altered: SUBSEQ should construct fresh lists + (test (equal nums '(1 2 3 4 5))))