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)
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en