I try to replace a certain element E in a list with another list K at all the main list levels.
(defun replaceList(l e k)
(cond
((null l) nil)
((equal e (car l)) (cons k (replaceList (cdr l) e k)))
((listp (car l))
((equal e (car (car l))) (cons k (replaceList (cdr (car l)) e k))))
(t (cons (car l) (replaceList (cdr l) e k)))))
Example:
(replaceList '(3 1 2 (6 1) 7 (5 (5 (3 1))) 9) '1 '(99 99))
--> (3 (99 99) 2 (6 (99 99)) 7 (5 (5 (3 (99 99) ) ) ) 9)
I get something with lambda expression as error message.
Also,i tried instead of the listp(car l)
"block" :
((listp (car l)) (cons k (replaceList (cdr (car l)) e k)))
.
I get something weird :
(2 1 3 ( 6 1 7) 7 1 2 )
-> (2 (99 99) 3 (99 99) (99 99) 7)