Joachim De Beule writes:

 > (defmacro my-defrecord [name [& fields] & body]
 >   `(defrecord ~name ~fields
 >      MyProtocol
 >      (do-something [this] this)
 >      ~@body))
 > 
 > But then when I call 
 > 
 > (my-defrecord R [content]), 
 > 
 > which expands into the following (valid) code:
 > 
 > (defrecord R (content) tmp-protocol (do-sth [this] this)),
 > 
 > Then I get the RunTimeException "No such var: this"? Any ideas?

For a detailed explanation, see this:

  http://onclojure.com/2010/02/23/generating-deftype-forms-in-macros/

As for solutions, the preferred one is

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

but you can also try

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

if for some reason you want the argument of do-something be called
exactly "this".

Konrad.

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