我正在尝试测试以下记录类型:
(defrecord FirstOrderState [datum matrix]
State
;; implementation goes here ...
)
我尝试根据上述类型进行分支,但没有得到我需要的结果
(def state (->FirstOrderState datum matrix))
(= (type state) composer.algorithm.markov.state.FirstOrderState)
=> false
但是,查看 state
的类型确认它应该匹配:
(type state)
=> composer.algorithm.markov.state.FirstOrderState
这似乎应该有效,因为类似的检查结果为 true
:
(= (type []) clojure.lang.PersistentVector)
=> true
我在这里缺少什么?使用下面的 hack 提供了一个解决方案,但不是很优雅:
(= (str (type state)) (str composer.algorithm.markov.state.FirstOrderState))
=> true
最佳答案
我的第一个猜测是您已经重新加载了包含记录类型定义的命名空间并且该state
在其他地方定义(可能在REPL),所以composer.algorithm.markov.state.FirstOrderState
现在引用的类与创建 state
时使用的类不同。
REPL 演示:
user=> (defrecord Foo [])
user.Foo
user=> (def foo (->Foo))
#'user/foo
user=> (= (type foo) Foo)
true
user=> (defrecord Foo [])
user.Foo
user=> (= (type foo) Foo)
false
关于clojure - 基于 Clojure 类型的比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20366130/