Hi Joachim.

On Mon, Apr 2, 2012 at 3:51 PM, Joachim De Beule
<joachim.de.be...@gmail.com> wrote:
> which expands into the following (valid) code:
>
> (defrecord R (content) tmp-protocol (do-sth [this] this)),

how did you get that expansion? Try this:

  user=> (macroexpand-1 '(my-defrecord R [content]))
  (clojure.core/defrecord R (content) user/MyProtocol
(user/do-something [user/this] user/this))

Now it's obvious why it fails: Clojure's syntax-quote expands "this"
to a symbol in the current namespace which, of course, doesn't exist.
The idiomatic way to hygienically introduce local variables (function
arguments in this case) is to suffix them with #, i.e.:

  (defmacro my-defrecord [name [& fields] & body]
    `(defrecord ~name ~fields
       MyProtocol
       (do-something [this#] this#)
       ~@body))

HTH,
Moritz

-- 
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

Reply via email to