Hi, Am 28.05.2009 um 18:50 schrieb CuppoJava:
The macro I'm attempting to write is: (defblockfn my_block_fn [arg1 arg2 func] (op1 arg1) (func) (op2 arg2)) Becomes: (defn -my_block_fn [arg1 arg2 func] (op1 arg1) (func) (op2 arg2)) (defmacro my_block_fn [arg1 arg2 & tail] `(-my_block_fn arg1 arg2 (fn [] ~...@tail))) The recursive backquotes are really confusing me. I would be extremely appreciative if someone can explain step-by-step how to reason with backquotes within backquotes.
(defmacro defblockfn [fn-name args & body] (let [fn-name-star (symbol (name (ns-name *ns*)) (str (name fn-name) "*"))] `(do (defn ~fn-name-star ~args ~...@body) (defmacro ~fn-name [a# b# & tail#] `(~'~fn-name-star ~a# ~b# (fn [] ~...@tail#)))))) You are right with the nested backticks. It's confusing. I didn't find out how to resolve function name other than doing it explicitly. One technique, which was helpful was to just call the defblockfn macro and then expand the call to freshly defined macro. (defblockfn foo [a b c] ...) (macroexpand-1 '(foo :a :b :c)) Hope this helps. Sincerely Meikel
smime.p7s
Description: S/MIME cryptographic signature