Source
(defmethod p-delete-if (test (list persistent-cons)
&key (from-end nil) (start 0) end count key)
;; DO: Implement FROM-END.
;; DO: Write tests.
(declare (ignore from-end))
(unless key
(setq key #'identity))
;; Move list to start position.
(let ((tail list)
(prev nil))
(loop repeat start
do (setq prev tail
tail (p-cdr tail)))
;; The real work.
(let ((nr-deleted 0))
(loop for i from start do
(if (or (p-endp tail)
(and end (= i end))
(and count (>= nr-deleted count)))
(return-from p-delete-if list)
(if (funcall test (funcall key (p-car tail)))
;; Delete the element.
(progn
(if prev
(setf (p-cdr prev) (p-cdr tail))
(setq list (p-cdr tail)))
;; Keep count.
(incf nr-deleted))
;; Don't delete anything.
(setq prev tail)))
;; Keep moving.
(setq tail (p-cdr tail)))))
;; Return the (possibly modified) list.
list)
Source Context