I've several functions (from others) that interrogate lists but I can't find one that can look at a nested list and rebuild a list in the same format. Confusing, sorry.
How to I take (setq CAPS '(("A" ("B" ("C")) ("D")) ("E"))) and using (strcase get '(("a" ("b" ("c")) ("d")) ("e"))?
S
Solved! Go to Solution.
Solved by scottbolton. Go to Solution.
Solved by martti.halminen. Go to Solution.
@scottbolton wrote:I've several functions (from others) that interrogate lists but I can't find one that can look at a nested list and rebuild a list in the same format. Confusing, sorry.
How to I take (setq CAPS '(("A" ("B" ("C")) ("D")) ("E"))) and using (strcase get '(("a" ("b" ("c")) ("d")) ("e"))?
S
(defun map-tree (func tree) (cond ((null tree) nil) ((vl-consp tree) (cons (map-tree func (car tree)) (map-tree func (cdr tree)))) (T (func tree))))
_$ (map-tree (lambda (s)(strcase s t)) caps)
(("a" ("b" ("c")) ("d")) ("e"))
_$ (map-tree ascii caps)
((65 (66 (67)) (68)) (69))
_$ (map-tree sqrt (cons 56 89))
(7.48331 . 9.43398)
--
Thanks, Martti. This looks good. I'll need to see how I can modify this to perform a more complex "func" - the (strcase example was simplified.
If I run in to problems I'll be back!
S
@scottbolton wrote:I'll need to see how I can modify this to perform a more complex "func" - the (strcase example was simplified.
This should work for any single-argument function, as long as it produces a result and doesn't crash.
--
Martti,
So this (very simple) function is what I have:
(defun tester (arg)
(cons arg (strcase arg T))
)
(map-tree tester '(("A" ("B" ("C")) ("D")) ("E")))
'((("A" . "a") (("B" . "b") (("C" . "c"))) (("D" . "d"))) (("E" . "e")))
Now I can start to go places with it. Thanks for your help.
S