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: defined macro (closure)
location: extension
source file: init.lsp
Common LISP compatible: yes
supported on: all machines


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


MAPCAN applies the <function> to the succesive CARs of each of the lists <listN>. Each of the lists supplies one of the arguments to <function>. MAPCAN is similar to MAPCAR, except that the MAPCAN macro returns a list that is constructed via the destructive NCONC function 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 'list '(1 2 3) '(a b c) )       ; returns ((1 A) (2 B) (3 C))
(mapcan 'list '(1 2 3) '(a b c) )       ; returns (1 A 2 B 3 C)
(mapcan 'list '(a b c)                  ; different length lists
           '(1 2 3 4 5 6))              ;   returns (A 1 B 2 C 3)

NOTE: Remember that MAPCAN uses NCONC and so it deals with its list arguments destructively. It is often used when you want to remove NIL entries from the resulting list - because NCONC will take out the NILs.

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).

NOTE: The macros MAPCAN and MAPCON are created in the INIT.LSP file. If they do not exist in your XLISP system, you might be having a problem with INIT.LSP. Before you start XLISP, look in the directory you are currently in, and check to see if there is an INIT.LSP.

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