Clojure macro problem

clojure

Solution

The link seth posted as a comment to your question contains the answer (the culprit is the way arguments to anonymous functions are handled); the following, using a gensym argument, should work:

(defmacro prototype [structure obj]
  `(apply struct ~structure (map (fn [x#] (~obj x#)) (keys ~obj))))

Problem

I'm trying to create a function to create a new basewith another struct as a base, and as a start I attempted to make a macro that would create a new struct with the same fields as the old one. The macro I have which i thought should do this is below, but it is giving the following error: ``` java.lang.Exception: Can't use qualified name as parameter: user/p1__132 ``` Macro: ``` (defmacro prototype [structure obj] `(apply struct ~structure (map #(~obj %) (keys ~obj)))) ``` Example of use: ``` (defstruct bintree :data :left :right) (def a (struct bintree 3)) (prototype bintree a) ``` The desired output in this case would be ``` {:data 3 :left nil :right nil} ```

Original source