Mapcan
The Lisp function mapcan works much like mapcar, but with a different way of gathering results:
(defun filter (lst predicate)
(mapcan #'(lambda (item)
(if (funcall predicate item)
(list item)
'()))
lst) )
>(filter '(a 2 or 3 and 7) 'numberp)
()(2)()(3)() (7)
(2 3 7)
>(filter '(a 2 or 3 and 7) 'symbolp)
(a)()(or)()(and)()
(A OR AND)