Question

I have the following record type that I am trying to test:

(defrecord FirstOrderState [datum matrix]
  State
  ;; implementation goes here ...
  )

I am trying to branch based on the above type, but am not getting the results I need

(def state (->FirstOrderState datum matrix))

(= (type state) composer.algorithm.markov.state.FirstOrderState)
=> false

However, looking at the type of state confirms that it should match:

(type state)
=> composer.algorithm.markov.state.FirstOrderState

This seems like it should work, as a similar check results in true:

(= (type []) clojure.lang.PersistentVector)
=> true

What is it that I am missing here? Using the below hack provides a solution, but not very elegant:

(= (str (type state)) (str composer.algorithm.markov.state.FirstOrderState))
=> true
Was it helpful?

Solution

My first guess would be that you have reloaded the namespace containing the definition of the record type and that state is defined elsewhere (possibly at the REPL), and so composer.algorithm.markov.state.FirstOrderState now refers to a different class from the one it used to at the time when state was created.

Demo at the 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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top