I am trying to create a function to create a new basewith a different structure as a base, and as a start I tried to create a macro that would create a new structure with the same fields as the old one. The macro I thought should do it below, but it gives 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))))
Usage example:
(defstruct bintree :data :left :right) (def a (struct bintree 3)) (prototype bintree a)
In this case, the desired result will be
{:data 3 :left nil :right nil}
clojure
Nathaniel flath
source share