I wrote a macro for creating a record
(defmacro def-entity [name & value]
`(do
(defrecord ~name (vector ~@value))
))
and I created one entity
(def-entity p a b)
But when I try to create a concrete instance
(def something (p. “a” “b”))
I get this message java.lang.IllegalArgumentException: No matching ctor found for class user.p (repl-1:40).
So I have to provide 3 parameters, like this
(def someone (p. “a” “b” “x”))
And it puts the values like this
(-> someone :a)
"b"
(-> neko :p)
nil
I don’t seem to understand what is happening?
As
defrecordis itself a macro, and expects the fields of the record to be passed in as a vector literal, you should better avoid passing a symbol referring to a vector, and really construct a vector literal as part of your macro work:Which results in:
In contrast, your version results in the following, which doesn’t use a vector literal as input to
defrecord:In facts, I can’t even use your version in Clojure 1.4: