Is there such a procedure in the standard of the Scheme, and yes, what is it called?

I searched for the name of the procedure, which applies the tree structure of the procedures to the tree structure of the data, giving a tree structure of the results - all three trees have the same structure.

Such a procedure may be signed:

(map-tree data functree)

Its return value will be the result of elementary application of functree elements on the corresponding data elements.

Examples (assuming the procedure is called map-tree):

Example 1:

(define * 2 (lambda (x) (* 2 x)))
; and similar definitions for * 3 and * 5

(map-tree '(100 (10 1))' (* 2 (* 3 * 5)))

will give a result

(200 (30 5))

Example 2:

(map-tree '(((aa. ab) (bb. bc)) (cc. (cd. ce)))
        '((car cdr) cadr))

gives the result

((aa bc) cd)

SLIB, .

?
, ?

+3
2

. ( map-traversing, ). , map.

(define (map-traversing func data)
  (if (list? func)
      (map map-traversing func data)
      (func data)))

, :

(map-traversing `((,car ,cdr) ,cadr) '(((aa . ab) (bb . bc)) (cc cd . ce)))

SRFI 26. ( (cut * 2 <>) (lambda (x) (* 2 x)).)

(map-traversing `(,(cut * 2 <>) (,(cut * 3 <>) ,(cut * 5 <>))) '(100 (10 1)))

, , .

+3

, :

(define (map-traversing func data)
  (if (list? func)
      (map map-traversing func data)
      (apply (eval func (interaction-environment)) (list data))))

. Guile - (-) Unbound. , (-- 5) (- 5), .

2: [1], (schem-report-environment 5) (null-environment 5) (use-modules (ice-9 r5rs))

[1]: http://www.mail-archive.com/bug-guile@gnu.org/msg04368.html 'Re: guile -c "(schem-report-environment 5)" == > : Unbound variable: schem-report-environment '

+1

Source: https://habr.com/ru/post/1697178/


All Articles