I have recently started learning clojure and am reading The Joy of Clojure to get to grips with it. I have a question regarding a code segment in the Macros chapter (8), on page 166
(defmacro domain [name & body]
`{:tag :domain, ;`
:attrs {:name (str '~name)}, ;'
:content [~@body]})
As I understand it, body is a sequence like structure with all arguments except the first one. If so, in the third line, why are we unquote-splicing (~@) and putting the values in a vector again. Why not just do ~body instead of [~@body]? What is the difference?
I am sorry but I am finding it really hard to grasp the whole macros thingy (coming from python).
Edit: After a bit of experimentation, I found that this works,
(defmacro domain2 [name & body]
`{:tag :domain, ;`
:attrs {:name (str '~name)}, ;'
:content '~body})
and along with the results I got from Joost's answer, I think I know what is happening here. body is being represented as a list, and so if I don't put a ' in front of ~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}