How to map a function over several values?

I have a function `foo-function` that takes the variable `x` and performs a specific action. The variable `x` comes before the definition of `foo-function`:

``````(defvar x "value1")

(defun foo-function ()
(blabalabla x))
``````

I would like to define a new function `foo-function2` which takes several variables `value1, value2, value3, ....` of `x` (the number of variables is indeterminate) and runs the function `foo-function` for these variables, i.e., the following action:

``````(foo-function2 "value1" "value2" "value3", ...)
``````

It should result in the execution of `foo-function` for the values `value1, value2, value3, ....` of `x`.

How do I define this function?

Looks like you want `mapcar`. From the docstring:

`(mapcar FUNCTION SEQUENCE)`

Apply FUNCTION to each element of SEQUENCE, and make a list of the results. The result is a list just as long as SEQUENCE. SEQUENCE may be a list, a vector, a bool-vector, or a string.

``````(defun identity-fnx (x)
x)

(mapcar #'identity-fnx '(1 2 3)) ; => (1 2 3)

(defvar x '(a b c d))
(mapcar #'identity-fnx x)        ; => (a b c d)
``````
• n.b. Use `mapc` instead to avoid accumulating the return value sequence, if you don't want that. Commented Jan 7, 2015 at 21:13
• @phils: right on; I wasn't sure if he wanted to accumulate or not. And another n.b. on your n.b. is to use a more general option like `cl-map` (compare How can I map over a vector and get a vector?).
– Dan
Commented Jan 7, 2015 at 21:18
• Little nitpick: `identity` is built-in :)
– user227
Commented Jan 8, 2015 at 10:16