As we should know, Clojure’s map can be applied to a sequence:
(map #(* %1 %1) [1 2 3]) ; (1)
..or to more than one, in this way:
(map vector [0 1] [2 1]) ; (2)
;=> ([0 2] [1 1])
Now I want to obtain the same result as (2), but I have the arguments stored inside a sequence. In other words, the following does not give the desired result:
(map vector [[0 1] [2 1]]) ; (3)
;=> ([[0 1]] [[2 1]])
So I’ve written this simple macro, where umap stands for “unsplice map”:
(defmacro umap [fun args-list]
"umap stands for unspliced map.
Let args-list be a list of args [a1 a2 ... an].
umap is the same of (map fun a1 a2 .. an)"
`(map ~fun ~@args-list))
Obviously it works like a charm:
(umap vector [[0 1] [2 1]]) ; (4)
;=> ([0 2] [1 1])
So here’s my question: am I reinventing the wheel?
Is there another way to do the same as (4)?
Bye and thanks in advance,
Alfredo
applyunpacks all of the elements in the sequence at the end of the argument list.