fdef for defmulti?

709 views
Skip to first unread message

Patrik Sundberg

unread,
Aug 18, 2016, 8:32:01 AM8/18/16
to Clojure
Hi,

Am I right to think you can't currently fdef a defmulti function? I tried and when running tests using clojure.spec.test/instrument I see:
1. Unhandled java.lang.ClassCastException
   clojure.spec.test$spec_checking_fn$fn__12959 cannot be cast to
   clojure.lang.MultiFn

                  core.clj: 1806  clojure.core/get-method
                  core.clj: 1806  clojure.core/get-method
           time_series.clj:  474  tulos.time-series/eval181936/fn

So I guess what happens is the fdef+instrument adds a normal fn wrapper, which then isn't a multi method and it breaks down.

Has this been discussed before? Any plans? I didn't find anything.

Thanks,
Patrik

Alex Miller

unread,
Aug 18, 2016, 1:23:17 PM8/18/16
to Clojure
There are several kinds of functions that can't currently be spec'ed (primitive, interned, maybe protocol fns?, multi methods). Some of those will ultimately be fixed, some (interned) will probably not.

Alex Miller

unread,
Aug 18, 2016, 1:27:08 PM8/18/16
to Clojure
I should mention that a half step is to spec the dispatch function used by the multimethod. That covers the front-end.

Patrik Sundberg

unread,
Aug 19, 2016, 6:42:27 AM8/19/16
to Clojure
What I meant was that you can spec the defmulti, and code runs just fine, but you can't instrument it. As then you end up with the instrumentation wrapper not being a multimethod, so things break. That's how I read the stack trace. It'd seem possible for instrument to wrap the multimethod with a multimethod stub, so perhaps that's a change to consider.

Yehonathan Sharvit

unread,
Feb 11, 2017, 4:29:14 PM2/11/17
to Clojure
Any update about defmulti and fdef?

Derek Thurn

unread,
Jun 29, 2017, 2:47:36 PM6/29/17
to Clojure
I'm also interested in this functionality. Is there an existing JIRA issue we can follow for allowing specs for multimethods?

Alex Miller

unread,
Jun 29, 2017, 3:39:09 PM6/29/17
to Clojure
I don't think there is a jira issue for it, feel free to add it. Not currently a priority for us but if someone wanted to work on it, I'd be happy to review.

Tim Sauerwein

unread,
Apr 6, 2018, 3:23:35 PM4/6/18
to Clojure
Because fdef is not available for defmulti, I find myself writing a dispatch function by hand instead of using a multimethod.
Reply all
Reply to author
Forward
0 new messages