The documentation for the ->
and ->>
macros state that the forms after the first parameter are wrapped into lists if they are not lists already. So the question is why does this not work for #()
and (fn ..)
forms? The reason is that both forms are in list form at the time the macro expands.
For example
(-> 3 (fn [x] (println x)))
gets the (fn [x] ...)
form at expansion time, so the macro thinks “great, it’s a list, I’ll just insert the 3 in the second position of the (fn ..)
list.” Invoking macroexpansion, this is what we get:
(fn 3 [x] (println x))
which of course doesn’t work. Similarly for #()
:
(-> 3 #(println %))
is expanded to
(fn* 3 [p1__6274#] (println p1__6274#))
That’s why we need the extra parens.