I want to write a macro that runs a 'defstruct' using a list of names,
like below:
;; My tag names
(def tags '("name" "age"))
;; The macro
(defmacro def-fields [name tgs]
`(defstruct ~name ~@(map #(symbol (str ":" %)) tgs))
)
;; Using the macro to define a struct based on 'tags'
(def-fields fs tags)
;; Create an instance of the struct
(def testfs (struct fs "Peter" "5"))
;; end
It fails with:
(def-fields fs tags)
java.lang.RuntimeException: java.lang.RuntimeException:
java.lang.RuntimeException: java.lang.IllegalArgumentException: Don't
know how to create ISeq from: Symbol (NO_SOURCE_FILE:8)
What do I do wrong here?
Per
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---