I'm having some trouble writing macros which use destrucutred arguments. Here is an example:
(defmacro defny
[n args & forms]
`(defn ~n ~args ~@forms))
(defmacro defnz
[n f args & forms]
`(defn ~n ~args
(do
(~f ~@args)
~@forms)))
(defny y
[{:keys [value] :as args}]
(println "Y ARGS" args)
(println "Y VALUE" value))
(defnz z y
[{:keys [value] :as args}]
(println "Z ARGS" args)
(println "Z VALUE" value))
Here, I have two macros, defny which simply calls through to defn, and defnz, which does the same, but additionally accepts another function which invokes prior to the function body with defnz's args.
When I invoke z, I expect to see both values and args printed out the same, but instead I get:
(z {:value 1})
Y ARGS {:keys [1], :as {:value 1}}
Y VALUE nil
Z ARGS {:value 1}
Z VALUE 1
=> nil
I can see why this is happening, the destructured args {:keys [1] :as {:value 1}} are getting passed to y, but I'm not sure how to fix the macro defnz so that the destructured args can be passed in properly.
macroexpandandmacroexpand-1to see what code your macros are producing. - Piotrek Bzdyl