Technically, there's no possibility of variable capture, but you should use gensyms:
(defmacro defrecord-ifn [name & args] `(defrecord ~name ~...@args clojure.lang.IFn (invoke [this# key#] (get this# key#)))) Thanks, Alyssa On Dec 30, 9:29 pm, Alex Baranosky <alexander.barano...@gmail.com> wrote: > I've been playing with making a macro to encapsulate Stuart's post, like > this: > > (defmacro defrecord-ifn [name & args] > `(defrecord ~name ~...@args > clojure.lang.IFn > (invoke [this key] (get this key)))) > > (defrecord-ifn Foo [a b c]) > > (def foo (Foo. "A" "B" "C")) > > (prn (map foo [:a :c])) => ("A", "C") > > I get the error: > > "No such var: user/this". I guess this is because it is expanding 'this' to > 'user/this'. What is the proper way to get a macro like this to expand > properly? > > Alex -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en