X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fsequence.lisp;h=6ac3ebfbe1e73bf3f5ec7b76739a127adad69fea;hb=7832783e9c05cce427c25f007fae72d285dd0fc2;hp=7b8fa4e518d68d9a6f8ab8c74e6f82cd0b0b5520;hpb=d385125fc92582ccbea9323381106af53b3f46c9;p=jscl.git diff --git a/src/sequence.lisp b/src/sequence.lisp index 7b8fa4e..6ac3ebf 100644 --- a/src/sequence.lisp +++ b/src/sequence.lisp @@ -33,14 +33,11 @@ (let ((,elt (aref ,nseq ,index))) ,@body)))))) -(defun find (item seq &key key (test #'eql)) - (if key - (do-sequence (x seq) - (when (funcall test (funcall key x) item) - (return x))) - (do-sequence (x seq) - (when (funcall test x item) - (return x))))) +(defun find (item seq &key key (test #'eql testp) (test-not #'eql test-not-p)) + (do-sequence (x seq) + (when (satisfies-test-p item x :key key :test test :testp testp + :test-not test-not :test-not-p test-not-p) + (return x)))) (defun find-if (predicate sequence &key key) (if key @@ -51,12 +48,14 @@ (when (funcall predicate x) (return x))))) -(defun position (elt sequence &key (test #'eql)) - (do-sequence (x seq index) - (when (funcall test elt x) +(defun position (elt sequence &key key (test #'eql testp) + (test-not #'eql test-not-p)) + (do-sequence (x sequence index) + (when (satisfies-test-p elt x :key key :test test :testp testp + :test-not test-not :test-not-p test-not-p ) (return index)))) -(defun remove (x seq) +(defun remove (x seq &key key (test #'eql testp) (test-not #'eql test-not-p)) (cond ((null seq) nil) @@ -64,7 +63,8 @@ (let* ((head (cons nil nil)) (tail head)) (do-sequence (elt seq) - (unless (eql x elt) + (unless (satisfies-test-p x elt :key key :test test :testp testp + :test-not test-not :test-not-p test-not-p) (let ((new (list elt))) (rplacd tail new) (setq tail new)))) @@ -72,7 +72,8 @@ (t (let (vector) (do-sequence (elt seq index) - (if (eql x elt) + (if (satisfies-test-p x elt :key key :test test :testp testp + :test-not test-not :test-not-p test-not-p) ;; Copy the beginning of the vector only when we find an element ;; that does not match. (unless vector @@ -133,15 +134,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)