Emacs has built-in Common Lisp library, which introduces plenty of Common Lisp functions and macros, but with the cl-
prefix. There is no reason to avoid this library. cl-mapcar
is what you want:
(cl-mapcar '+ '(1 2 3) '(10 20 30)) ; (11 22 33)
With dash
list manipulation library (see the installation instructions), you can use -zip-with
(remember: -zip-with
is the same as cl-mapcar
applied to 2 lists):
(-zip-with '+ '(1 2 3) '(10 20 30)) ; (11 22 33)
I don't know an elegant way to implement a -zip-with
equivalent for 3 arguments. But you may use -partial
from dash-functional
package, which comes with dash
(functions from dash-functional
require Emacs 24). -partial
partially applies the function, so these 2 function invocations below are equivalent:
(-zip-with '+ '(1 2) '(10 20)) ; (11 22)
(funcall (-partial '-zip-with '+) '(1 2) '(10 20)) ; (11 22)
Then, you can use it with a -reduce
function:
(-reduce (-partial '-zip-with '+) '((1 2 3) (10 20 30) (100 200 300)))
; (111 222 333)
You can wrap it into a function with &rest
keyword, so this function would accept varying amount of arguments instead of a list:
(defun -map* (&rest lists)
(-reduce (-partial 'zip-with '+) lists))
cl-mapcar
and make sure to(require 'cl-lib)
. – Grus