I'm trying to create a function to insert an item in a list in deep position.
example:
I have this list:
(("zzz" ("abc" ("www")) ("qqq" ("ccc" ("bbb"))))))
I want to add/insert new list ("111" "222" "333") in ("bbb" )
to obtain this:
(("zzz" ("abc" ("www")) ("qqq" ("ccc" ("bbb" ("111" "222" "333")))))))
I can not find a good way to rebuild the sublists inside list.
Note that list items values are unique, never duplicate.
this is my code:
(defun deepinsert
(lst upd new
)
(deepinsert
(cdr lst
) upd new
) )
)
)
(T
(or (deepinsert
(nth 0 lst
) upd new
) (deepinsert
(cdr lst
) upd new
) )
)
)
out
)
(deepinsert '(("zzz" ("abc" ("www")) ("qqq" ("ccc" ("bbb"))))) "bbb" '("111" "222"))
=> ("www" "abc" "zzz" ("ccc" ("111" "222")) "bbb" "aaa")