1

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 Answer 1

2

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)))
Sign up to request clarification or add additional context in comments.

1 Comment

That eval is needed for such a simple purpose disturbs me. Much about macros does, though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.