Two following examples of using a function in a macro result in evaluations without errors.
(defmacro works []
(let [f (fn [] 1)]
`(~f)))
(works)
;; => 1
(defn my-nullary-fn []
(fn [] 2))
(defmacro also-works []
(let [f (my-nullary-fn)]
`(~f)))
(also-works)
;; => 2
However,
(defmacro does-not-work []
(let [f (constantly 3)]
`(~f)))
(does-not-work)
throws
java.lang.IllegalArgumentException: No matching ctor found
for class clojure.core$constantly$fn__4051
Likewise,
(defn my-unary-fn [x]
(fn [] x))
(defmacro also-does-not-work []
(let [f (my-unary-fn 4)]
`(~f)))
(also-does-not-work)
throws
java.lang.IllegalArgumentException No matching ctor found
for class user$my_other_fn$fn__12802
What might be the reason? Is there a difference between function objects returned by fn, my-nullary-fn, constantly and my-unary-fn?
I'm running Clojure 1.5.1.
CLJ-946 might be related.