Written by
Aaron Bell
on
on
Unquote splicing (`~@`) evaluates before stripping parentheses
To understand macros, I needed to understand unquote splicing. I used to think it peeled the parentheses off, but no:
(= `(+ ~@(map #(+ 2 %) [1 2 3 4])) '(clojure.core/+ map #(+ 2 % ) [1 2 3 4]))`.
;;=> false
Evident with the ~
unquote symbol, it lets the onion sprout (evaluate) first before peeling its layers 😄:
(= `(+ ~@(map #(+ 2 %) [1 2 3 4])) '(clojure.core/+ 3 4 5 6))
;;=> true