Multi-methods can be extended ... to the extent of what their dispatch-function defines.
So for what you want to work, you should have this notion of "from where is the multi-method called" wired in the dispatch function. Imagineyou could redefine the dispatch function (which you can not for print-method, or this would be very hackish I guess). Even there, you'll have to solve the "how does the dispatch method know from which namespace the multimethod is called ?" ...). Generally, dispatch methods will work on the arguments of the multi-method. Surely, they could also work by doing introspection of the call stack by hooking into clojure internals, and also you could make them work differently by having them inspect global variables ... huck !!! What you want isn't even easily solved by OOP like in javascript, where you can change every method implementation of every object, because you would like the method implementation to be chosen depending on the caller of the method, not just the callee or a function of the other arguments of the method ... HTH, -- Laurent 2010/1/5 Gabi <bugspy...@gmail.com>: > Hmm.. I hoped I could avoid this. Multi-methods should be extended, > not copied and then extended :) > But if there is no other way, I probably settle for this cumbersome > solution.. > > > On Jan 5, 11:21 pm, Laurent PETIT <laurent.pe...@gmail.com> wrote: >> How about creating your own print-method multimethod in a lib of your >> own, and in your libs, excluding clojure.core/print-method and >> importing your-lib/print-method instead. >> >> Then, in your-lib, make the default print-method invocation just call >> clojure.core/print-method, create your own private hierarchy, and >> provide defmethods for those types you want to provide with your own >> implementation of defmethod ... >> >> Cant' think of something better, for now ... >> >> HTH, >> >> -- >> Laurent >> >> 2010/1/5 Gabi <bugspy...@gmail.com>: >> >> > Hi >> > I am trying to extend Clojures' print-method using defmethod for a >> > library I develop.: >> > How can I do this without affecting users of my lib (i want only my >> > lib to be affected )? >> >> > (derive clojure.lang.Fn ::fn) >> > (prefer-method print-method ::fn java.lang.Object) >> >> > (defmethod print-method ::fn >> > [o w] >> > (.write w "Some Fn") >> >> > This is quite nice, but I would like to use a private hierarchy for >> > the above, but cant. (print-method is defined on global hierarchy) >> > What should I do ? >> >> > -- >> > 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 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 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