chickadee » scheme » map

(map proc list[1] list[2] ...)procedure

The lists must be lists, and proc must be a procedure taking as many arguments as there are lists and returning a single value. Map applies proc element-wise to the elements of the lists and returns a list of the results, in order. The dynamic order in which proc is applied to the elements of the lists is unspecified.

Like in SRFI-1, this procedure allows the arguments to be of unequal length; it terminates when the shortest list runs out. This is a CHICKEN extension to R5RS.

(map cadr '((a b) (d e) (g h)))   
                ===>  (b e h)

(map (lambda (n) (expt n n))
     '(1 2 3 4 5))                
                ===>  (1 4 27 256 3125)

(map + '(1 2 3) '(4 5 6))                 ===>  (5 7 9)

(let ((count 0))
  (map (lambda (ignored)
         (set! count (+ count 1))
         count)
       '(a b)))                         ===>  (1 2) or (2 1)