I think auto-gensym (using #
syntax) can shadow itself when used recursively, which seems like a bug. jumar confirmed this happens in 1.10.3, 1.6.0, 1.3.0, and 1.0.0
(defmacro recursive-macro-1 [[x & more :as xs] acc]
(if (seq xs)
`(let [x# ~x]
(recursive-macro-1 ~more (conj ~acc x#)))
acc))
(defmacro recursive-macro-2 [[x & more :as xs] acc]
(if (seq xs)
(let [gx (gensym 'x)]
`(let [~gx ~x]
(recursive-macro-2 ~more (conj ~acc ~gx))))
acc))
(comment
(recursive-macro-1 [1 2] []) ;; => [2 2]
(recursive-macro-2 [1 2] []) ;; => [1 2]
)
I would expect recursive-macro-1
to produce the same results as recursive-macro-2
but you can see, from running clojure.walk/macroexpand-all on these forms, that the shadowing prevents this:
;; auto-gensym - the name of the local binding is the same in the nested let*
(let* [x__10885__auto__ 1]
(let* [x__10885__auto__ 2]
(conj (conj [] x__10885__auto__) x__10885__auto__)))
;; gensym
(let* [x11095 1]
(let* [x11096 2]
(conj (conj [] x11095) x11096)))