I am pretty new to Clojure, so what I am trying to do may make no sense. I am completely open to alternative ways to get similar functionality
I have a Heap protocol and two records that implement that protocol: (defprotocol Heap (min [this] (insert [this x])) In heap1.clj (defrecord Heap1 [n] (min [this] (comment do stuff)) (insert [this x] (comment insert stuff))) In heap2.clj (defrecord Heap2 [n] (min [this] (comment do some different stuff)) (insert [this x] (comment insert stuff in a different way)) I found it useful to use extend-type to define this protocol on nil as well. In heap1.clj (extend-type nil Heap (min [this] (throw (Exception.)) (insert [this x] (->Heap1 x) This is all still working. In heap2.clj I would like to define another implementation of heap on nil, for when I require/use heap2.clj . In heap2.clj (extend-type nil Heap (min [this] (throw (Exception.)) (insert [this x] (->Heap2 x) Now, in the tests for heap1.clj where I am not requiring the heap2 namespace (or even know about it), my tests are failing because (insert nil 1) now returns a heap2 record. At this point I decided I obviously did not understand what extend-type actually does, and tried to do a bit of research, but I couldn't really find anything that went very in-depth. If someone could provide an alternative to what I am trying to do, that would be great. Alternatively, it would be useful for someone to explain what extend-type does under the covers a bit. -- -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.