我有一些带有一些预定义函数和记录的 clojure 文件
;outer.clj
(ns outer )
(defn foo [a] (println a))
(defrecord M [id])
现在使用文件
;inner.clj
(ns inner (:use outer ))
(foo 2) ;works fine
(println (:id (M. 4))) ;throws IllegalArgumentException: Unable to resolve classname: M
为什么函数导入正常但记录定义没有?我应该如何导入它?
最佳答案
因为 defrecord 会在“幕后”生成一个 JVM 类,所以您需要导入该类...
;inner.clj
(ns inner
(:use outer )
(:import outer.M)
(foo 2) ;works fine
(println (:id (M. 4))) ; works with import
关于function - 在多个命名空间中使用记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11773357/