-> parens apply-str , , . ->, :
(defmacro ->
"Threads the expr through the forms. Inserts x as the
second item in the first form, making a list of it if it is not a
list already. If there are more forms, inserts the first form as the
second item in second form, etc."
([x] x)
([x form] (if (seq? form)
(with-meta `(~(first form) ~x ~@(next form)) (meta form))
(list form x)))
([x form & more] `(-> (-> ~x ~form) ~@more)))
The relevant part is when it deals with two arguments xand form. If formis seq, is xinserted as the second argument in this list. Otherwise, the macro places formand xit in the list. This means that you can use the bare character as an abbreviation for a list containing one character.
user> (macroexpand '(-> 123 (foo)))
(foo 123)
user> (macroexpand '(-> 123 foo))
(foo 123)
source
share