XLISP > XLISP 2.0  -  Contents  -  Reference  -  Previous | Next

mapc


Type:   -   function (subr)
Source:   -   xllist.c

Syntax

(mapc function list1 [list2 ... ])
function - a function definition like a lambda form or a function name
listN - a list or list expression
returns - the first list of arguments

Description

The 'mapc' function 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 'mapc' function returns a list that is equivalent to the first list 'list1'. It's purpose is to perform operations that have side-effects. If the lists are of different lengths, the shortest list will determine the number of applications of 'function'.

Examples

(mapc 'princ '(hi there bob))         ; prints HITHEREBOB
                                      ;   returns (HI THERE BOB)

(mapc '+ '(1 2 3) '(1 2 3))           ; returns (1 2 3)
                                      ;   there were no side effects

(mapc (lambda (x y) (print (+ x y)))  ; define a function with side effects
      '(1 2 3) '(1 2 3))              ;   prints 2 4 6 
                                      ;   returns (1 2 3)

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.

See the mapc function in the XLISP 2.0 manual.

  Back to Top


XLISP > XLISP 2.0  -  Contents  -  Reference  -  Previous | Next