I have to define a function filter
that has as arguments a predicate and a list and returns as value the initial list with THE ONLY ATOMS -for every level of depth- which satisfy the initial predicate (keeping attention at NIL value in order to mantain the list structure).
Example:
(filter 'evenp '(24 5 (7) d (((4))) 3 ()))
(24 () (((4))) ())
The code i was thinking is like this:
(defun filter (pred list)
(cond ((null list) nil)
((funcall pred (car list))
(cons (car list)
(filter pred (cdr list))))
(T (filter pred (cdr list)))))
How can i implement the depth fact, keeping so the round bracket as displayed in the example?
thank you all