Hello guys. I’m learning web apps with Clojure from scratch and I wanted to make a macro that would hold a common template using Hiccup for my pages, like this:
(defmacro defpage
[elements]
(html
(include-css "https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css")
elements))
I’m calling my macro with some functions inside the structure representing the HTML. That’s a dumb example for sake of simplicity:
(defpage [:p (+ 1 2)])
Well, I know that macro content is not evaluated by default, so the result is this:
<link href=\"https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css\" rel=\"stylesheet\" type=\"text/css\" /><p>+12</p>
See the “+12”. Would be better if it was a “3”. If I tell my macro to (eval elements)
this works as I expect, but I wonder if this does not kinda “breaks” the purpose of macros.
What are your thoughts?