Next: Folding of Lists, Previous: Searching Lists, Up: Lists [Contents][Index]

- standard procedure:
**map***procedure list list …*¶ It is an error if

`procedure`does not accept as many arguments as there are`list`s and return a single value.The

`map`

procedure applies`procedure`element-wise to the elements of the`list`s and returns a list of the results, in order. If more than one`list`is given and not all lists are the same length,`map`

terminates when the shortest list runs out. The`list`s can be circular, but it is an error if all of them are circular. It is an error for`procedure`to mutate any of the lists. The dynamic order in which`procedure`is applied to the elements of the`list`s is unspecified. If multiple returns occur from`map`

, the values returned by earlier returns are not mutated.`(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 7)) ⇒ (5 7 9) (let ((count 0)) (map (lambda (ignored) (set! count (+ count 1)) count) '(a b))) ⇒ (1 2) or (2 1)`

- obsolete procedure:
**map****knil proc list*¶_{1}list_{2}… Deprecated, use

`fold-right`

instead. Equivalent to(fold-right (lambda (e

_{1}e_{2}… acc) (cons* (`proc`e_{1}) (`proc`e_{2}) … acc))`knil``list`_{1}`list`…)_{2}

- SRFI 1 procedure:
**append-map***procedure list list …*¶ Similar to

`map`

except that the results of applying`procedure`to the elements of`list`s are concatenated together by`append`

rather than by`cons`

. The following are equivalent, except that the former is more efficient:(append-map

`procedure``list`_{1}`list`…) (apply append (map_{2}`procedure``list`_{1}`list`…))_{2}

- obsolete procedure:
**append-map****knil proc list*¶_{1}list_{2}… Deprecated, use

`fold-right`

instead. Equivalent to(fold-right (lambda (e

_{1}e_{2}… acc) (append (`proc`e_{1}) (`proc`e_{2}) … acc))`knil``list`_{1}`list`…)_{2}

- SRFI 1 procedure:
**append-map!***proc list list …*¶ Similar to

`map`

except that the results of applying`proc`to the elements of`list`s are concatenated together by`append!`

rather than by`cons`

. The following are equivalent, except that the former is more efficient:(append-map!

`proc``list``list`…) (apply append! (map`proc``list``list`…))

- obsolete procedure:
**append-map*!***knil proc list*¶_{1}list_{2}… Deprecated, use

`fold-right`

instead. Equivalent to(fold-right (lambda (e

_{1}e_{2}… acc) (append! (`proc`e_{1}) (`proc`e_{2}) … acc))`knil``list`_{1}`list`…)_{2}

- standard procedure:
**for-each***procedure list list …*¶ It is an error if

`procedure`does not accept as many arguments as there are`list`s.The arguments to

`for-each`

are like the arguments to`map`

, but`for-each`

calls`procedure`for its side effects rather than for its values. Unlike`map`

,`for-each`

is guaranteed to call`procedure`on the elements of the`list`s in order from the first element(s) to the last, and the value returned by`for-each`

is unspecified. If more than one`list`is given and not all lists have the same length,`for-each`

terminates when the shortest`list`runs out. The`list`s can be circular, but it is an error if all of them are circular.It is an error for

`procedure`to mutate any of the lists.(let ((v (make-vector 5))) (for-each (lambda (i) (vector-set! v i (* i i))) '(0 1 2 3 4)) v) ⇒ #(0 1 4 9 16)

- SRFI 1 procedure:
**any***predicate list list …*¶ Applies

`predicate`across the`list`s, returning true if`predicate`returns true on any application.If there are

*n*list arguments`list`…_{1}`list`, then_{n}`predicate`must be a procedure taking*n*arguments and returning a boolean result.`any`

applies`predicate`to the first elements of the`list`parameters. If this application returns a true value,`any`

immediately returns that value. Otherwise, it iterates, applying`predicate`to the second elements of the`list`parameters, then the third, and so forth. The iteration stops when a true value is produced or one of the lists runs out of values; in the latter case,`any`

returns`#f`

. The application of`predicate`to the last element of the`list`s is a tail call.Note the difference between

`find`

and`any`

—`find`

returns the element that satisfied the predicate;`any`

returns the true value that the`predicate`produced.Like

`every`

,`any`

’s name does not end with a question mark—this is to indicate that it does not return a simple boolean (`#t`

or`#f`

), but a general value.(any integer? '(a 3 b 2.7)) => #t (any integer? '(a 3.1 b 2.7)) => #f (any < '(3 1 4 1 5) '(2 7 1 8 2)) => #t

- SRFI 1 procedure:
**every***predicate list list …*¶ Applies

`predicate`across the`list`s, returning true if`predicate`returns true on every application.If there are

*n*list arguments`list`…_{1}`list`, then_{n}`predicate`must be a procedure taking*n*arguments and returning a boolean result.`every`

applies`predicate`to the first elements of the`list`parameters. If this application returns false,`every`

immediately returns false. Otherwise, it iterates, applying`predicate`to the second elements of the`list`parameters, then the third, and so forth. The iteration stops when a false value is produced or one of the`list`s runs out of values. In the latter case,`every`

returns the true value produced by its final application of`predicate`. The application of`predicate`to the last element of the`list`s is a tail call.If one of the

`list`s has no elements,`every`

simply returns`#t`

.Like

`any`

,`every`

’s name does not end with a question mark—this is to indicate that it does not return a simple boolean (`#t`

or`#f`

), but a general value.

Next: Folding of Lists, Previous: Searching Lists, Up: Lists [Contents][Index]