Generating readable code for IDEs is not a good reason. You should think carefully about variable capture and decide which you want. Usually, in a macro-generated defn, I do want to capture the parameters, so I would use ~'this.
On Dec 30, 11:54 pm, André Thieme <splendidl...@googlemail.com> wrote: > Am 31.12.2010 03:29, schrieb Alex Baranosky: > > > > > > > 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? > > Others have already pointed to this# . > I just would like to add that you can as well use ~'this in some > cases, where your macros generate defns. The advantage is that some > editors (like emacs) will show you the parameter vector and that would > show a useful name and not this_auto_foobarbaz123456 . -- 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