Creating records using macro in Clojure -
i want define vector values want use in record , pass vector macro creates record.
(def keys ['data1 'data2 'data3]) (defmacro make-record [n v & body] `(defrecord ~n ~v ~@body)) (make-record vud vud-keys) (macroexpand-1 '(make-record type keys)) -> (defrecord type keys)
what want is:
(macroexpand-1 '(make-record type keys)) -> (defrecord type ['data1 'data2 'data3])
it looks need evaluate arguments during macroexpansion. eval
does.
(def keys '[data1 data2 data3]) (defmacro make-record [name keys] `(defrecord ~name ~(eval keys)))
Comments
Post a Comment