mapcar

AutoCad AutoLISP Functions

 
mapcar
 
 
 

Returns a list that is the result of executing a function with a list (or lists) supplied as arguments to the function

(mapcar functionlist1... listn)

Arguments

function

A function.

list1... listn

One or more lists. The number of lists must match the number of arguments required by function.

Return Values

A list.

Examples

Command: (setq a 10 b 20 c 30)

30

Command: (mapcar '1+ (list a b c))

(11 21 31)

This is equivalent to the following series of expressions, except that mapcar returns a list of the results:

(1+ a)
(1+ b)
(1+ c)

The lambda function can specify an anonymous function to be performed by mapcar. This is useful when some of the function arguments are constant or are supplied by some other means. The following example, entered from the Visual LISP Console window, demonstrates the use of lambda with mapcar:

_$ (mapcar  '(lambda (x) 
                (+ x 3)
    
                ) 
    
               '(10 20 30)
    
      )
    
(13 23 33)