michalmarczyk / ctries.clj

Ctries implemented in Clojure, see Prokopec, Bronson, Bagwell, Odersky
60 stars 3 forks source link

hook for print-method? #1

Closed pdenno closed 8 years ago

pdenno commented 8 years ago

Would it be possible to put in a hook so that users could call their own print-method ? N. B. I'm still sort of new to Clojure so maybe there is something I'm missing, but what I'm doing now is essentially copying your print method (defmethod print-method ctries.clj.Ctrie [ctrie ^java.io.Writer w] ... into my program and wrapping the body in an if that check for ctries that match some characteristics of the ones I intend to print differently.

Also pprint of ctries in cider/emacs hangs the listener.

pdenno commented 8 years ago

[Answering my own question] There are indeed better ways to do this than what I suggested above, e.g. wrap your object in a record, use metadata....

michalmarczyk commented 8 years ago

Indeed, I would say that one should generally be circumspect about providing print-method implementations for types one does not own, doubly so when the original type comes with one. An extra wrapper type would seem like a safer solution. (In fact, one should generally not implement multimethods / protocols unless one owns at least one of the type and multimethod / protocol involved.)

If you do feel you need to replace the provided implementation, you can get at it using clojure.core/get-method before supplying your own replacement in the way you describe above; in that way you can reuse the original method directly rather than cutting-and-pasting its code.