I have a nested list, and I am trying to non-destructively replace all its elements (inside the nested list as well). That is, given my input list
\'(1 \'(2
You have to realize that 'foo
is syntactic sugar for (quote foo), so when you use quotes inside an already-quoted list, this:
'(1 '(2 3 4) '(5 6 7) 8 9)
evaluates to this:
(1 (quote (2 3 4)) (quote (5 6 7)) 8 9)
So when you substitute all the list elements with 0, you get:
(0 (0 (0 0 0)) (0 (0 0 0)) 0 0)
You either need to not put extra quotes in your examples, or you need to handle the quote operator specially in subs-list:
(defun subs-list (list value)
"Replaces all elements of a list of list with given value"
(loop for elt in list
collect
(cond
((listp elt)
(subs-list elt value))
((eq 'quote elt)
elt)
(t
value))))