Structural Informatics Group (SIG) logo
Home | Projects | Demos | Downloads | Publications | Local Info | About Us | New site
Go to the first, previous, next, last section, table of contents.



type: function (subr) 
location: built-in
source file: xllist.c
Common LISP compatible: yes
supported on: all machines


(mapcar <function> <list1> [ <list2> ... ] )
        <function>      -       a function definition (like a LAMBDA) 
                                or a function name
        <listN>         -       a list or list expression


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)                     ; different length lists
           '(1 2 3 4 5 6))              ;   returns (2 4 6)

NOTE: The use of the <function> will work properly when it is a quoted symbol (which is the name of the function), an unquoted symbol (whose value is a function) or a closure object (like a LAMBDA).

BUG NOTE: The proper syntax for <function> when <function> is a lambda expression is, for example (mapcar #'(lambda (arg1 arg2) (+ arg1 arg2)) '(1 2)), NOT (mapcar '(lambda (arg1 arg2) (+ arg1 arg2)) '(1 2)). That is, the #' 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.

Go to the first, previous, next, last section, table of contents.