6.6.9.8 List Mapping

List processing is very convenient in Scheme because the process of iterating over the elements of a list can be highly abstracted. The procedures in this section are the most basic iterating procedures for lists. They take a procedure and one or more lists as arguments, and apply the procedure to each element of the list. They differ in their return value.

Scheme Procedure: map proc arg1 arg2 …
Scheme Procedure: map-in-order proc arg1 arg2 …
C Function: scm_map (proc, arg1, args)

Apply proc to each element of the list arg1 (if only two arguments are given), or to the corresponding elements of the argument lists (if more than two arguments are given). The result(s) of the procedure applications are saved and returned in a list. For map, the order of procedure applications is not specified, map-in-order applies the procedure from left to right to the list elements.

Scheme Procedure: for-each proc arg1 arg2 …

Like map, but the procedure is always applied from left to right, and the result(s) of the procedure applications are thrown away. The return value is not specified.

See also SRFI-1 which extends these functions to take lists of unequal lengths (Fold, Unfold & Map).