Mapping: map and foreach

In mathematics, a mapping f: A B assigns to each element of the set A (the domain) an element of the set B (the range). f(x) is the element of set B corresponding to element x of set a.

The function (map f list_1 list_2 ...) applies the function f to successive members of the lists list_i and returns a list of the results. (in Common Lisp, map is called mapcar and for-each is called mapc.)

> (map car '((f . 2) (m . 4)))
(f m)

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

The function (for-each f list_1 list_2 ...) works like map but does not make a list of the result values. It is used when fn is executed for its side-effects rather than for its values.

Contents    Page-10    Prev    Next    Page+10    Index