The mapcan function 'mapcar' applies the 'function' to the succesive cars of each of the lists 'listN'. Each of the lists supplies one of the arguments to 'function'. The 'mapcar' function returns a list that is constructed from the results of the 'function' applications. If the lists are of different lengths, the shortest list will determine the number of applications of 'function'.
(mapcar '+ '(1 2 3) '(1 2 3)) ; returns (2 4 6) (mapcar 'princ '(1 2 3)) ; prints 123 ; returns (1 2 3) (mapcar '+ '(1 2 3) '(1 2 3 4 5 6) ; different length lists ; returns (2 4 6)
Note: The use of the 'function' will work properly when it is a quoted symbol [the name of the function], an unquoted symbol whose value is a function or a closure object like a lambda form.
Bug: The proper syntax for 'function' when 'function' is a lambda expression is, for example:
(mapcar #'(lambda (arg1 arg2) (+ arg1 arg2)) '(1 2))
and not:
(mapcar '(lambda (arg1 arg2) (+ arg1 arg2)) '(1 2))
That is, the #' [function] read macro must be present. This error should be caught by the XLISP interpreter, but it is not, with the result that very obscure garbage collection bugs occur. [I still haven't tested this with Nyquist.]
See the
mapcar
function in the