Replies: 2 comments 3 replies
-
Keywords have both 1-arity and 2-arity for "not-found", so I don't think this is so curious. All args are passed to both the dispatch fn and the resulting method. |
Beta Was this translation helpful? Give feedback.
-
The dispatch function is called with the same amount of arguments as the |
Beta Was this translation helpful? Give feedback.
-
Source of idea
On shadow-cljs slack chat, @p-himik was asking if shadow-cljs/cljs should help out with an error when calling a multimethod with the wrong arity. While he was talking about the compiler, I chimed in wondering if clj-kondo could help with a linter here.
@p-himik offered the following short and sweet snippet to show clj-kondo does not yet lint this type of thing:
Mechanics of
defmulti
anddefmethod
I started writing up a clj-kondo issue to propose a feature to lint for this use case, when I realized that I did not fully understand the mechanics of
defmulti
anddefmethod
arities. @borkdude and I started to explore.Question 1: Should arities of
defmethod
s and theirdefmulti
dispatch fn all be equal?Here's an example where arities do match:
But here's an example where the
defmulti
dispath fn is arity-1 and itsdefmethod
s are arity-2.Is this a normal/desirable thing to do?
Question 2: Should
defmethod
s arities all be equal?Although this is possible, it seems like a bad idea for
defmethod
s for a singledefmulti
to have different arities?Question 3: Does multi-arity come into play?
Yes, it can, at least for
defmethod
s.Question 4: Does ClojureScript behave the same as Clojure?
I expect linting rules should be the same, but the above experiments were all in Clojure, not ClojureScript.
Question 5: ??
Beta Was this translation helpful? Give feedback.
All reactions