Reputation: 58806
I wish to make a clojure deftype which implements Clojure Hashmaps. I realise that I can implement the Clojure Interfaces to make my deftype Hashable and Sequable, but what do I need to include to get my deftype to play nice with the Clojure STM so that I can do:
(def a (ref (MyType.)))
and then to perform dosync operations such as conj and cons in an STM safe manner?
Upvotes: 2
Views: 210
Reputation: 5881
You problem is allready solved by records they are what you describe a type/class but with interfaces like Hashable and Sequable (and more).
You can just put your record in a ref like anyother hashmap. Don't see the problem here.
Upvotes: 2
Reputation: 1822
(def a (ref MyType))
doesn't make much sense because you are putting the class MyType
in a ref.
The type that you put into a ref should ideally be an immutable type as the body of dosync
should be free of side effects.
Upvotes: 1