title: LISP - removing an element from a list with nested lists
body: <p>I need to remove an element from a list which contain inner lists inside. The predefined element should be removed from every inner list too. </p>
  
  <p>I have started working with the following code:</p>
  
  <pre><code>(SETQ L2 '(a b ( a 2 b) c 1 2 (D b (a s 4 2) c 1 2 a) a )) ; defined my list 
  
  ; Created a function for element removing
  (defun elimina (x l &amp;optional l0)
  (cond (( null l)(reverse l0))
  ((eq x (car l))(elimina x (cdr l) l0))
  (T (elimina x (cdr l) (cons (car l) l0))))
  )
  
  (ELIMINA 'a L2) 
  </code></pre>
  
  <p>But unfortunately it removes only elements outside the nested lists.</p>
  
  <p>I have tried to create an additional function which will remove the element from the inner lists.</p>
  
  <pre><code>(defun elimina-all (x l)
  (cond ((LISTP (CAR L))(reverse l)(elimina x (car l)))
  (T (elimina-all  x (CDR L)))
  )
  )
  </code></pre>
  
  <p>but still unsuccessfully.</p>
  
  <p>Can you please help me to work it out?</p>
  
  <p>Thank you in advance.</p>