Clojure: how to create a record inside a function?
问题 In clojure, I would like to create a record inside a function. I tried: (defn foo [] (defrecord MyRecord [a b]) (let [b (MyRecord. "1" "2")])) But it causes an exception: java.lang.IllegalArgumentException: Unable to resolve classname: MyRecord Any idea? 回答1: The key points You should only use defrecord at top level. 1 So, if you do need a custom record type, you should define it outside of foo (at some point in your code which gets processed before foo 's definition). Otherwise, you could