User Tools

A PCRE internal error occured. This might be caused by a faulty plugin

====== Function MAP ====== ====Syntax==== * **map** //result-type// //function// ''&rest'' //sequences''+''// → //result// ====Arguments and Values==== * //result-type// - a **[[CL:Types:sequence]]** //[[CL:Glossary:type specifier]]//, or **[[CL:Constant Variables:nil]]**. * //function// - a //[[CL:Glossary:function designator]]//. //function// must take as many arguments as there are //sequences//. * //sequence// - a //[[CL:Glossary:proper sequence]]//. * //result// - if //result-type// is a //[[CL:Glossary:type specifier]]// other than **[[CL:Constant Variables:nil]]**, then a //[[CL:Glossary:sequence]]// of the //[[CL:Glossary:type]]// it denotes; otherwise (if the //result-type// is **[[CL:Constant Variables:nil]]**), **[[CL:Constant Variables:nil]]**. ====Description==== Applies //function// to successive sets of arguments in which one argument is obtained from each //[[CL:Glossary:sequence]]//. The //function// is called first on all the elements with index ''0'', then on all those with index ''1'', and so on. The //result-type// specifies the //[[CL:Glossary:type]]// of the resulting //[[CL:Glossary:sequence]]//. **map** returns **[[CL:Constant Variables:nil]]** if //result-type// is **[[CL:Constant Variables:nil]]**. Otherwise, **map** returns a //[[CL:Glossary:sequence]]// such that element ''j'' is the result of applying //function// to element ''j'' of each of the //sequences//. The result //[[CL:Glossary:sequence]]// is as long as the shortest of the //sequences//. The consequences are undefined if the result of applying //function// to the successive elements of the //sequences// cannot be contained in a //[[CL:Glossary:sequence]]// of the //[[CL:Glossary:type]]// given by //result-type//. If the //result-type// is a //[[CL:Glossary:subtype]]// of **[[CL:Types:list]]**, the result will be a //[[CL:Glossary:list]]//. If the //result-type// is a //[[CL:Glossary:subtype]]// of **[[CL:Types:vector]]**, then if the implementation can determine the element type specified for the //result-type//, the element type of the resulting array is the result of //[[CL:Glossary:upgrade|upgrading]]// that element type; or, if the implementation can determine that the element type is unspecified (or ''*''), the element type of the resulting array is **[[CL:Types:t]]**; otherwise, an error is signaled. ====Examples==== <blockquote> (map '[[CL:Types:string]] #'([[CL:Symbols:lambda]] (x y) ([[CL:Functions:char]] "01234567890ABCDEF" ([[CL:Functions:mod]] ([[CL:Functions:math-add|+]] x y) 16))) '(1 2 3 4) '(10 9 8 7)) <r>"AAAA" </r> ([[CL:Macros:defparameter]] *seq* '("lower" "UPPER" "" "123")) <r>("lower" "UPPER" "" "123")</r> (map [[CL:Constant Variables:nil]] #'[[CL:Functions:nstring-upcase]] *seq*) <r>[[CL:Constant Variables:NIL]] </r> *seq* <r>("LOWER" "UPPER" "" "123") </r> (map '[[CL:Types:list]] #'- '(1 2 3 4)) <r>(-1 -2 -3 -4) </r> (map '[[CL:Types:string]] #'([[CL:Symbols:lambda]] (x) ([[CL:Special Operators:if]] ([[CL:Functions:oddp]] x) #\1 #\0)) '(1 2 3 4)) <r>"1010" </r> </blockquote> <blockquote> (map '(vector * 4) #'cons "abc" "de") should signal an error </blockquote> ====Affected By==== None. ====Exceptional Situations==== An error of type **[[CL:Types:type-error]]** must be signaled if the //result-type// is not a //[[CL:Glossary:recognizable subtype]]// of **[[CL:Types:list]]**, not a //[[CL:Glossary:recognizable subtype]]// of **[[CL:Types:vector]]**, and not **[[CL:Constant Variables:nil]]**. Should be prepared to signal an error of type type-error if any //sequence// is not a //[[CL:Glossary:proper sequence]]//. An error of type **[[CL:Types:type-error]]** should be signaled if //result-type// specifies the number of elements and the minimum length of the //sequences// is different from that number. ====See Also==== * {\secref\TraversalRules} ====Notes==== None. \issue{SEQUENCE-TYPE-LENGTH:MUST-MATCH} \issue{CONCATENATE-SEQUENCE:SIGNAL-ERROR} \issue{SEQUENCE-TYPE-LENGTH:MUST-MATCH} \issue{MAPPING-DESTRUCTIVE-INTERACTION:EXPLICITLY-VAGUE} \issue{CONCATENATE-SEQUENCE:SIGNAL-ERROR} \issue{FUNCTION-TYPE:X3J13-MARCH-88} \issue{CONCATENATE-SEQUENCE:SIGNAL-ERROR}