Welcome! Please see the About page for a little more info on how this works.

+13 votes
in Multimethods by
retagged by

CLJS has:

cljs.user=> (source dispatch-fn)
(defn dispatch-fn
  "Given a multimethod, return it's dispatch-fn."
  [multifn] (-dispatch-fn multifn))

Can we have this core fn on the JVM as well?

2 Answers

0 votes
by
selected by
0 votes
by

What is the use case for this in ClojureScript and/or why do you want it in Clojure?

by
The use case would be for writing cross-platform/dialect code: CLJ/CLJS/babashka

Typically I try to only expose functions and rather not implementation details/things you have to get at using interop.  There are a few programs (including clojure.spec.alpha) that use this field, that could be written in user space without relying on this field. But to be fair, there aren't that many programs. It would probably mostly a Clojure-implementor feature than useful for every day users, similar to why https://github.com/clojure/clojure/blob/7697d5da77a319077e71343f76fa204327881de4/src/clj/clojure/core.clj#L4380 and destructure are exposed

https://grep.app/search?q=.dispatchFn&filter[lang][0]=Clojure
by
Here is the CLJS issue / patch that added this:

https://clojure.atlassian.net/browse/CLJS-1144

Note that CLJS also added default-dispatch-val.
by
Context from Slack:

borkdude:: Feb 27th at 2:34 PM
Why is this not in clojure.core on the JVM?
cljs.user=> (source dispatch-fn)
(defn dispatch-fn
  "Given a multimethod, return it's dispatch-fn."
  [multifn] (-dispatch-fn multifn))
/cc @wilkerlucio
:point_up:
2 replies
alexmiller  9 months ago
Add an ask question, seems like a reasonable thing to want
by
I'm asking because while this issue has a number of up votes here, I find very few uses of this method in CLJS or lookups of the field in CLJ code, mostly in pretty advanced usage, so this does not seem particularly critical.
by
Some more background here why it would be nice to have this in core: https://blog.michielborkent.nl/using-clojure-spec-alpha-with-babashka.html
It would allow other Clojure implementations to implement and use their own core function instead of exposing it in several other namespaces that aren't really re-used.
...