File: tree-map

package info (click to toggle)
scheme9 2025.08.12-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,080 kB
  • sloc: lisp: 16,752; ansic: 11,869; sh: 806; makefile: 237; sed: 6
file content (14 lines) | stat: -rw-r--r-- 509 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
S9 LIB  (tree-map procedure1 procedure2 pair)  ==>  pair

Apply PROCEDURE2 to each node of the tree rooted at PAIR
to which the predicate PROCEDURE1 applies. Return a fresh
tree.

(tree-map number? list '((a . 1) (b . 2)))
  ==>  ((a . (1)) (b . (2)))
(tree-map (lambda (x) (and (pair? x)
                           (string? (car x))
                           (string? (cdr x))))
          (lambda (x) (string-append (car x) (cdr x)))
          '(("foo" . "bar") ("bar" . "baz")))
  ==>  ("foobar" "barbaz")