Why do you want to do this? It's possible that it would improve performance if you generated loads of these records, but you would have to effectively compile your whole program at runtime in order to have the static type information needed to get the improved performance. Most of the time someone wants to do this it's some sort of misguided OOP or "safety" feature that they want to control what's in their hashmaps, and in those cases the answer is "well stop putting stuff into your hashmaps if you don't want it getting there".
On Dec 18, 11:56 am, Bill Robertson <billrobertso...@gmail.com> wrote: > I'm trying to define records based on meta data read in at runtime, > and I'm attempting to write a function that extracts name and attrs > and passes them to defrecord, but I don't understand how to > dynamically create the symbol for the record name. > > e.g. > > user=> (defrecord (symbol "foo" "bar") [a b]) > java.lang.ClassCastException: clojure.lang.PersistentList cannot be > cast to clojure.lang.Symbol (NO_SOURCE_FILE:5) > > Attempting to define fields in any way that I can guess at fail. > > e.g. > > user=> (def fields [(symbol "a")]) > #'user/fields > user=> (defrecord foo fields) > IllegalArgumentException Don't know how to create ISeq from: > clojure.lang.Symbol clojure.lang.RT.seqFrom (RT.java:487) > user=> (defrecord foo (var fields)) > user.foo > user=> (user/map->foo {:a 67}) ;; funny > #user.foo{:var nil, :fields nil, :a 67} > > Short of generating a string and calling eval on it, is this possible? -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en