how to write a macro that calls defrecord?

2012-04-03 Thread Konrad Hinsen
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:

Re: how to write a macro that calls defrecord?

2012-04-03 Thread Alex Miller
You might find this useful for examples: http://david-mcneil.com/post/765563763/enhanced-clojure-records On Monday, April 2, 2012 8:51:23 AM UTC-5, Joachim De Beule wrote: Hi All, I need to define a number of similar records, so I wanted to write a macro for that, but I do not know how.

how to write a macro that calls defrecord?

2012-04-02 Thread Joachim De Beule
Hi All, I need to define a number of similar records, so I wanted to write a macro for that, but I do not know how. Basically, I tried the following: (defprotocol MyProtocol (do-something [this])) (defmacro my-defrecord [name [ fields] body] `(defrecord ~name ~fields MyProtocol

Re: how to write a macro that calls defrecord?

2012-04-02 Thread Herwig Hochleitner
You need to be careful when using syntax-quote (backtick `): It tries to resolve every symbol it encloses, as the compiler would: If it's use'd, the symbol is qualified with the origin ns, otherwise with the current ns (current during read time of the syntax-quote form, i.e. macro _definition_

Re: how to write a macro that calls defrecord?

2012-04-02 Thread Moritz Heidkamp
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