2

我有以下要测试的记录类型:

(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
4

1 回答 1

4

我的第一个猜测是您已经重新加载了包含记录类型定义并且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
于 2013-12-04T04:23:34.460 回答