Overview Clamps Packages CM Dictionary Clamps Dictionary Fomus
Next: mappend , Previous: map-proplist , Up: M , Home: Overview

Clamps Dictionary

map-tree

Function

(map-tree fn tree &key (test (lambda (elem) (not (consp elem)))))

Map function recursively and non-destructively on all leaf nodes of given tree (represented as a nested list). Leaf nodes are determind by applying #'test on the list containing them. If test returns t, the node is considered to be a leaf node. Return the modified tree as a new structure.

Arguments

fn Function to call on the leaf nodes.
tree List to traverse, possibly nested

Examples

(map-tree #'print '(1 (2 7 (8 9 ((17 15 (14)) 5 (3))))))
;; => (1 (2 7 (8 9 ((17 15 (14)) 5 (3)))))
;; output in the REPL:
1 
2 
7 
8 
9 
17 
15 
14 
5 
3 

(map-tree (lambda (x) (+ x 100)) '(1 (2 7 (8 9 ((17 15 (14)) 5 (3))))))
;; => (101 (102 107 (108 109 ((117 115 (114)) 105 (103)))))

Author: Orm Finnendahl

Created: 2025-02-18 Di 12:58

Validate