;; Append th element of lists that match predicate to the end of the collection list (mutated); ;; Return the appended collection (defun collect-if (predicate list &optional collection) (loop for x in list when (funcall predicate x) do (if (null collection) (setf collection (list x)) (nconc collection (list x))) finally (return collection))) (defun collect-if (predicate list &optional collection) (loop with coll = (cons nil collection) for x in list when (funcall predicate x) do (nconc collection (list x)) finally (return (cdr collection)))) (defun collect-if (predicate list &optional collection) (loop for x in list when (funcall predicate x) do (push x collection) finally (return collection)))