Reputation: 7374
I want to define a vector with all the values i want to use in my record and then pass this vector to a macro that creates my 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 is want is:
(macroexpand-1 '(make-record TYPE keys)) -> (defrecord TYPE ['data1 'data2 'data3])
Upvotes: 1
Views: 98
Reputation: 38809
It looks like you need to evaluate your arguments during macroexpansion.
This is what eval
does.
(def keys '[data1 data2 data3])
(defmacro make-record [name keys]
`(defrecord ~name ~(eval keys)))
Upvotes: 2