This macroexpansion looks fine to me... but still gives an error when you try to call (bar alex).
(defmacro bar
[a]
(let [b (keyword a)
f-gensym (gensym "f")]
`(let [~f-gensym (fn [& args#] ~b)]
(deftype ~a []
clojure.lang.ILookup
(valAt [this# k#] (~f-gensym this# k#))
(valAt [this# k# d#] (~f-gensym this# k# d#))))))
user=> (macroexpand-1 `(bar alex)) (pp)
...
(clojure.core/let
[f174 (clojure.core/fn [& args__160__auto__] :user/alex)]
(clojure.core/deftype
user/alex
[]
clojure.lang.ILookup
(user/valAt
[this__161__auto__ k__162__auto__]
(f174 this__161__auto__ k__162__auto__))
(user/valAt
[this__161__auto__ k__162__auto__ d__163__auto__]
(f174 this__161__auto__ k__162__auto__ d__163__auto__))))
Error when you call it:
user=> (bar alex)
CompilerException java.lang.RuntimeException: Unable to resolve symbol: f177 in this context, compiling:(NO_SOURCE_PATH:85)