![[LISPWORKS]](/image.pl?url=http%3a%2f%2fwww.lispworks.com%2fdocumentation%2fHyperSpec%2fBody%2f..%2fGraphics%2fLWSmall.gif&f=jpg&w=240)
![[Common Lisp HyperSpec (TM)]](/image.pl?url=http%3a%2f%2fwww.lispworks.com%2fdocumentation%2fHyperSpec%2fBody%2f..%2fGraphics%2fCLHS_Sm.gif&f=jpg&w=240)
Syntax:
mapresult-type function&rest sequences+ =>result
Arguments and Values:
result-type -- asequencetype specifier, ornil.
function---afunction designator.function must take as many arguments as there aresequences.
sequence---aproper sequence.
result---ifresult-type is atype specifier other thannil, then asequence of thetype it denotes; otherwise (if theresult-type isnil),nil.
Description:
Appliesfunction to successive sets of arguments in which one argument is obtained from eachsequence. Thefunction is called first on all the elements with index0, then on all those with index1, and so on. Theresult-type specifies thetype of the resultingsequence.
map returnsnil ifresult-type isnil. Otherwise,map returns asequence such that elementj is the result of applyingfunction to elementj of each of thesequences. The resultsequence is as long as the shortest of thesequences. The consequences are undefined if the result of applyingfunction to the successive elements of thesequences cannot be contained in asequence of thetype given byresult-type.
If theresult-type is asubtype oflist, the result will be alist.
If theresult-type is asubtype ofvector, then if the implementation can determine the element type specified for theresult-type, the element type of the resulting array is the result ofupgrading that element type; or, if the implementation can determine that the element type is unspecified (or*), the element type of the resulting array ist; otherwise, an error is signaled.
Examples:
(map 'string #'(lambda (x y) (char "01234567890ABCDEF" (mod (+ x y) 16))) '(1 2 3 4) '(10 9 8 7)) => "AAAA" (setq seq '("lower" "UPPER" "" "123")) => ("lower" "UPPER" "" "123") (map nil #'nstring-upcase seq) => NIL seq => ("LOWER" "UPPER" "" "123") (map 'list #'- '(1 2 3 4)) => (-1 -2 -3 -4) (map 'string #'(lambda (x) (if (oddp x) #\1 #\0)) '(1 2 3 4)) => "1010"(map '(vector * 4) #'cons "abc" "de") should signal an error
Affected By: None.
Exceptional Situations:
An error oftypetype-error must be signaled if theresult-type is not arecognizable subtype oflist, not arecognizable subtype ofvector, and notnil.
Should be prepared to signal an error oftypetype-error if anysequence is not aproper sequence.
An error oftypetype-error should be signaled ifresult-type specifies the number of elements and the minimum length of thesequences is different from that number.
See Also:
Section 3.6 (Traversal Rules and Side Effects)
Notes: None.