1
votes

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])
1

1 Answers

2
votes

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)))