I recently started to learn clojure and read the "Joy" clojure to handle this. I have a question about the code segment in the chapter "Macros" (8), on page 166
(defmacro domain [name & body] `{:tag :domain, ;` :attrs {:name (str '~name)}, ;' :content [ ~@body ]})
As I understand it, body is a sequence similar to a structure with all arguments except the first. If so, on the third line, why do we perform unquote-splicing ( ~@ ) and put the values ββin the vector again. Why not just ~body instead of [ ~@body ] ? What is the difference?
I am very sorry, but it is very difficult for me to understand all the macros (from python).
Edit: After a little experiment, I found that this works,
(defmacro domain2 [name & body] `{:tag :domain, ;` :attrs {:name (str '~name)}, ;' :content '~body})
and along with the results from Joost's answer, I think I know what is going on here. body is represented as a list, and therefore, if I do not put ' before ~body , clojure will try to evaluate it.
user=> (domain "sh" 1 2 3) {:content [1 2 3], :attrs {:name "sh"}, :tag :domain} user=> (domain2 "sh" 1 2 3) {:content (1 2 3), :attrs {:name "sh"}, :tag :domain}
source share