Reciprocating a deftypes method in Clojure

I want to implement transient and persistent! in my Clojure deftype. As far as I can tell, this means that you need to use another method, TransientMyThing, to implement the necessary methods. Well, so far these two classes need to know about each other in order to return to each other.

I think I can do this by reselling Clojure's make-transient and make-persistent functions, then defining deftype (referring to this function), then implementing functions with already existing types, but this seems pretty rude to me. Is there a better option?

Edit: this works, but still rude.

+6
source share
1 answer

In Clojure 1.3 and later, a slightly simpler solution is to rely on the constructor functions that Clojure creates for your demenops, → transitional and → permanent !. Since these are functions, not macros, you can forward them. Then you can use them, and not your own transients, and make them persistent, and you do not need to implement them yourself.

+4
source

Source: https://habr.com/ru/post/890841/


All Articles