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

- standard procedure:
**map***procedure list list …* `Procedure`must be a procedure taking as many arguments as there are`list`s. If more than one`list`is given, then they must all be the same length.`map`

applies`procedure`element-wise to the elements of the`list`s and returns a list of the results, in order from left to right. The dynamic order in which`procedure`is applied to the elements of the`list`s is unspecified; use`for-each`

to sequence side effects.`(map cadr '((a b) (d e) (g h))) ⇒ (b e h) (map (lambda (n) (expt n n)) '(1 2 3 4)) ⇒ (1 4 27 256) (map + '(1 2 3) '(4 5 6)) ⇒ (5 7 9) (let ((count 0)) (map (lambda (ignored) (set! count (+ count 1)) count) '(a b c))) ⇒ unspecified`

- 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 …* 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 to the last, and the value returned by`for-each`

is unspecified.(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]