Advertisement
Guest User

Untitled

a guest
Dec 5th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. ;; Append th element of lists that match predicate to the end of the collection list (mutated);
  2. ;; Return the appended collection
  3. (defun collect-if (predicate list &optional collection)
  4. (loop for x in list
  5. when (funcall predicate x)
  6. do (if (null collection)
  7. (setf collection (list x))
  8. (nconc collection (list x)))
  9. finally (return collection)))
  10.  
  11. (defun collect-if (predicate list &optional collection)
  12. (loop with coll = (cons nil collection)
  13. for x in list
  14. when (funcall predicate x)
  15. do (nconc coll (list x))
  16. finally (return (cdr coll))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement