求助: 递归的更改一个list

各位同学,我遇到一个需要递归解决的问题,自己有点绕晕了,请求协助

(and (regexp “jtysqy”) (or (regexp “tree1”) (regexp “tree2”)))

这个tree深度不是固定的,我需要一个函数,可以更改所有的 (regexp “xxx”)

;;tweaked from dash.el -tree-map
(defun tree-map (fn tree)
  "Apply FN to each element of TREE while preserving the tree structure."
  (cond
   ((null tree) nil)
   ((consp tree)
    (if (eq (car tree) 'regexp)
        (funcall fn tree)
        (mapcar (lambda (x) (tree-map fn x)) tree)))
   (t tree)))
(setq ls '(and (regexp "jtysqy") (or (regexp "tree1") (regexp "tree2"))))
;; (and (regexp "jtysqy") (or (regexp "tree1") (regexp "tree2")))
(tree-map (lambda (a) (cdr a)) ls)
;;(and ("jtysqy") (or ("tree1") ("tree2")))
1 个赞

有现成的库,不过单纯一个walk,用库有点小题大作