I want to implement transient
and persistent!
in my Clojure deftype. As far as I can tell, this means having another deftype, TransientMyThing, implement the necessary methods. Okay so far, but those two classes need to know about each other in order to return instances of each other.
I think I can do it by forward-declaring Clojure functions make-transient and make-persistent, then defining the deftype (by referring to that function), then implementing the functions with the now-existing types, but it seems pretty gross to me. Is there a better option?
Edit: that works, but it's still gross.
In Clojure 1.3 and later, a slightly simpler solution is to rely on the constructor functions that Clojure creates for your deftypes, ->transient and ->persistent!. Since those are functions, and not macros, you can forward declare them. Then you can use them, rather than your own make-transient and make-persistent, and you don't have to implement them yourself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With