Barry Margolin
9/11/2015 6:24:00 PM
In article <317ed58d-a5c0-4893-b04b-f09f9c38dfbb@googlegroups.com>,
schatzer.johann@gmail.com wrote:
> I have a large tree with many nested (:note "string") at any level, and am
> trying to replace any (:note "..") list with its string.
>
> ; this small example tree
> '(a (:note "a")
> (b (:note "abc"))
> (d e f (:note "de"))))
>
> ;should be converted into this one
> '(a "a"
> (b "abc")
> (d e f "de")))
>
> i.e. recursively find every sublist beginning with :note and replace it with
> its string
Like this:
(defun replace-note (tree)
(if (consp tree)
(if (eq (car tree) :note)
(cadr tree)
(cons (replace-note (car tree))
(replace-note (cdr tree))))
tree))
This returns a new tree with the substitutions, it's not done
destructively.
>
>
> I think also subst or subst-if could do such things, but am not able to
> compose a working function. help appreciated. thank you.
None of the SUBST family can do this, because the substitutions are
specified once in the arguments, they're not a function of the tree
contents.
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***