Hi,

Am 25.09.2009 um 22:49 schrieb Constantine Vetoshev:

(defmacro def-with-db-macro [macro-name open-fn close-fn]
 `(defmacro ~macro-name [[var# & open-args#] & body#]
    `(let [~var# (apply ~'~open-fn [...@open-args#])]
       (try
        ~...@body#
        (finally (~'~close-fn ~var#))))))

The problem is, that you quote the symbol you inject into the inner defmacro. Hence it does not get resolved. The solution in this case seems to be to syntax-quote the symbol correctly before injection. Replace the two ~'~ with ~~ and call the macro as (def-with-db-macro with-foo `open-foo `close-foo). This correctly resolves the symbols in the namespace calling def-with-db-macro and injects them into the with- foo expansion. I haven't really tested this, but it seems to be consistent with the macro machinery.

While searching for a workaround, I thought maybe I could capture the
functions I need during expansion of def-with-db-macro, but kept
getting a useless exception. I ended up reducing that problem to this:

(let [f1 #(inc %)]
 (defmacro m1 [x]
   `(~f1 ~x)))

(m1 12)
=> No message.
 [Thrown class java.lang.ExceptionInInitializerError]

This seems indeed useless at a first glance, but looking down the cause trace usually shows the real problem.

Sincerely
Meikel

Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to