clojure - deftype in defmacro with metadata -


let's suppose have deftype looking next way:

(deftype ^{a: a} name []) 

i want define macro generating deftype:

(defmacro dotype [name]   `(deftype ^{a :a} ~name [])) 

however, i'm losing information metadata.

(macroexpand-1 '(dotype t)) ;> (clojure.core/deftype t []) 

i tried use tricks vary-meta avoid using ^{} in macro. unfortunately, deftype doesn't support iobj interface (doesn't support metadata), , tries didn't work.

please suggest way implement macro. thanks!

this works me:

(deftype [])  (defmacro dotype [name]   `(deftype ~(with-meta name {:tag a}) []))  (binding [*print-meta* true]   (prn (macroexpand-1 '(dotype t))))  ; user=> (clojure.core/deftype ^user.a t []) 

note: metadata doesn't print default, have enable binding *print-meta* shown above, or else set in repl (set! *print-meta* true), setting permanently in repl print massive amount of uninteresting info screen, best avoid (!).


Comments