A set of high-level mapping functions is available in Common Lisp, to apply a function to the elements of one or more lists. They differ in the way in which the function is applied to the lists and how the final result is obtained. The following table summarize the differences and shows for each of them the equivalent LOOP form. *f* is the function to be applied, that must have a number of arguments equal to the number of lists; “applied to car” means that it is applied in turn to the elements of the lists, “applied to cdr” means that it is applied in turn to the lists, their cdr, their cddr, etc.; the “returns” column shows if the global result is the obtained by listing the results, concatenating them (so they must be lists!), or simply used for side-effects (and in this case the first list is returned).

Function | Applied to | Returns | Equivalent LOOP |
---|---|---|---|

(mapcar f l_{1}… l_{n}) | car | list of results | (loop for x_{1} in l_{1}… for x_{n} in l_{n} collect (f x_{1}… x_{n})) |

(maplist f l_{1}… l_{n}) | cdr | list of results | (loop for x_{1} on l_{1}… for x_{n} on l_{n} collect (f x_{1}… x_{n})) |

(mapcan f l_{1}… l_{n}) | car | concatenation of results | (loop for x_{1} in l_{1}… for x_{n} in l_{n} nconc (f x_{1}… x_{n})) |

(mapcon f l_{1}… l_{n}) | cdr | concatenation of results | (loop for x_{1} on l_{1}… for x_{n} on l_{n} nconc (f x_{1}… x_{n})) |

(mapc f l_{1}… l_{n}) | car | l_{1} | (loop for x_{1} in l_{1}… for x_{n} in l_{n} do (f x_{1}… x_{n}) finally (return l_{1})) |

(mapl f l_{1}… l_{n}) | cdr | l_{1} | (loop for x_{1} on l_{1}… for x_{n} on l_{n} do (f x_{1}… x_{n}) finally (return l_{1})) |

Note that, in all the cases, the lists can be of different lengths, and the application terminates when the shortest list is terminated.

Another couple of map functions are available: `map`

, that can be applied to sequences (strings, vectors, lists), analogous to `mapcar`

, and that can return any type of sequence, specified as first argument, and `map-into`

, analogous to `map`

, but that destructively modifies its first sequence argument to keep the results of the application of the function.