This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-05-23
Channels
- # announcements (12)
- # beginners (225)
- # calva (7)
- # cider (45)
- # clj-kondo (1)
- # cljdoc (1)
- # cljsrn (3)
- # clojure (112)
- # clojure-dev (45)
- # clojure-europe (6)
- # clojure-finland (2)
- # clojure-india (1)
- # clojure-nl (27)
- # clojure-spec (37)
- # clojure-uk (171)
- # clojurescript (39)
- # core-async (9)
- # cursive (22)
- # datascript (8)
- # datomic (50)
- # emacs (12)
- # figwheel-main (17)
- # fulcro (42)
- # garden (2)
- # hoplon (27)
- # jobs (4)
- # kaocha (8)
- # klipse (2)
- # luminus (2)
- # off-topic (9)
- # perun (33)
- # planck (2)
- # re-frame (9)
- # reagent (48)
- # reitit (5)
- # remote-jobs (1)
- # rum (2)
- # shadow-cljs (23)
- # slack-help (3)
- # spacemacs (18)
- # sql (7)
- # tools-deps (24)
- # unrepl (9)
- # vim (30)
In situations where you are using a dependency injection mechanism like component, it can sometimes be cumbersome to take advantage of multi fns, since you have to figure out a way to hand dependencies over to the method being installed
When the input of the multi-method is a map, we often use namespaced keys inside that map to provision components
I was wondering whether it could be considered to add an add-method
function which would essentially be (eliding a few things):
(defn add-method [^clojure.lang.MultiFn multifn dispatchval f] (.addMethod multifn dispatchval f))
I don’t understand the use case - can you flesh it out more?
To try to clarify: without resorting to interop, the only way to add a method on a multimethod if with defmethod
having a way to supply a dispatchvalue and function directly could be useful in some cases
(defn add-method [multi-fn dispath-value f]
(.addMethod ^clojure.lang.MultiFn multi-fn dispath-value f))
?I don't understand why defmethod isn't fine?
defmethod could just as easily have been called add-method (I think the "def" is really there to signal stateful var-level change, but you're getting that regardless)
@alexmiller I agree that defmethod is fine for use in closures, and my issue is not with the name
can you give an example where that's cumbersome?
that's not an example
I mean code :)
conceptually, I think it would be perfectly fine to have an add-method in core, that defmethod used, but which could be used directly if needed
but I want to be compelled that it's needed :)
Switching that over to defmethod is completely feasible but requires a bit more gymnastics
would be fine to ticket this. having a more complete example would be helpful particularly as this seems pretty specific to the lifecycle patterns imposed by component
We've discussed this internally, I don't think this is a good idea. Multimethods are global, and component is local. You can run multiple of the same system in parallel. This would prevent you from running tests at the same time as your REPL.
We have resorted to protocols when we need state, especially now that the metadata form is available.
@alexmiller I created https://clojure.atlassian.net/servicedesk/customer/portal/1/SUPPORT-5
no, that's ours
I am still working on the portal for issue filing so you can be a guinea pig :)