next up previous
Contents Next: maxmin (FUNCTIONS) Up: Appendix: Selected LISP Previous: listp (PREDICATE)

mapcar (FUNCTION)

Format: (mapcar <func> <lis1> . . . <lisN>)

Required arguments: 2

First argument names a function (usually quoted). Subsequent arguments must evaluate to lists.

Mapcar applies the named function successively to the first, second, third, etc. elements of the subsequent arguments and returns a list of the results, up to the length of the shortest list provided.

Examples:

>(mapcar '+ '(1 2 3))
(1 2 3)

>(mapcar '+ '(1 2 3) '(4 5 6))
(5 7 9)

>(mapcar '+ '(1 2 3) '(4 5 6) '(7 8 9))
(12 15 18)

>(mapcar '+ '(1 2) '(3 4 5))
(4 6)

>(mapcar '< '(1 2 3) '(4 5 0))
(T T NIL)

>(mapcar '< '(1 2 3) '(4 5))
(T T)



© Colin Allen & Maneesh Dhagat
November 1999