This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-02-28
Channels
- # announcements (11)
- # aws (1)
- # babashka (12)
- # babashka-sci-dev (6)
- # beginners (46)
- # biff (15)
- # calva (57)
- # clerk (6)
- # clj-kondo (50)
- # clj-together (1)
- # cljs-dev (14)
- # clojure (89)
- # clojure-doc (1)
- # clojure-europe (36)
- # clojure-nl (1)
- # clojure-norway (50)
- # clojure-spec (4)
- # clojure-uk (1)
- # clojurescript (56)
- # conjure (10)
- # cursive (1)
- # datalevin (2)
- # datomic (3)
- # fulcro (15)
- # honeysql (36)
- # hyperfiddle (74)
- # malli (19)
- # membrane (16)
- # off-topic (33)
- # pathom (6)
- # polylith (2)
- # reagent (14)
- # releases (2)
- # rum (5)
- # shadow-cljs (51)
- # sql (6)
- # tools-build (10)
- # xtdb (6)
Just got slightly bitten by the fact that there's no warning when a multimethod is passed a wrong amount of arguments. Is that something that's possible to add to shadow-cljs or is it on the CLJS side?
Doesn't seem like it:
$ echo '(defmulti f identity) (f)' | clj-kondo --lint -
linting took 20ms, errors: 0, warnings: 0
what if you add ^{:arglists ...}
metadata to the defmulti
?
kondo might be able to spot that
@U04V15CAJ, would raising a clj-kondo feature request issue for this be worthwhile?
Just so the intent is not lost - while it would certainly be valuable, I would still prefer for the compiler to also complain about it. :) It's much easier to notice when your code is not reloaded with a warning right there in the UI that's being developed.
@U2FRKM4TW, as I write up the kondo issue, I realize my defmulti
knowledge is limited.
All defmethod
s for a defmulti
would typically share the same arity, right?
Would it be warning-worthy if they did not?
I think that's a completely different task.
defmulti
+ calls to that function are one thing.
defmethod
match to its "parent" defmulti
is another.
But yeah, that might be something worth doing.
Thanks, so you were just originally talking about calling a defmulti
with 0 args when it needs at least one, is that right?
e.g. this should be a warning:
user=> (defmulti foo identity)
#'user/foo
user=> (defmethod foo 1 (fn [x y] y))
Ok, thanks folks, I've used defmulti
but have obviously forgotten the details of how it actually works!
I think I'll hold off on the kondo issue until I reboot my brain on it.
what I think is happening: the dispatch function is applied to the arguments (e.g. x, or x y) and then when there's a match for a defmethod, those same arguments are fed to the defmethod function
user=> (defmulti foo (fn [x y] y))
#'user/foo
user=> (defmethod foo 2 [x y] {:x x :y y})
#object[clojure.lang.MultiFn 0x78830d9a "clojure.lang.MultiFn@78830d9a"]
user=> (foo 1 2)
{:x 1, :y 2}
Ok, this is probably an extra weird example usage right?: (sorry shadow-cljs folks, maybe we should move this conversation elsewhere?)
❯ clj
Clojure 1.11.1
user=> (defmulti foo :dispatch)
#'user/foo
user=> (defmethod foo :d1 [x] {:x x})
#object[clojure.lang.MultiFn 0x2f879bab "clojure.lang.MultiFn@2f879bab"]
user=> (defmethod foo :d2 [x y] {:x x :y y})
#object[clojure.lang.MultiFn 0x2f879bab "clojure.lang.MultiFn@2f879bab"]
user=> (foo {:dispatch :d1})
{:x {:dispatch :d1}}
user=> (foo {:dispatch :d2} "moar")
{:x {:dispatch :d2}, :y "moar"}
user=> (foo {:dispatch :d2})
Execution error (ArityException) at user/eval156 (REPL:1).
Wrong number of args (1) passed to: user/eval150/fn--151
user=> (foo {:dispatch :d1} "moar")
Execution error (ArityException) at user/eval158 (REPL:1).
Wrong number of args (2) passed to: user/eval140/fn--141
ah you're right, the defmethods can vary in arity, but have at minimum the arity of the dispatch function... I think?
although I think you're creating your own footgun when you're using multimethods like this
I think it's safe to say that the amount of arguments must at least satisfy the dispatch function's arity's lower bound
and probably in 99% of cases the arity will be the same but we don't know this for sure
Yeah, that makes sense. I still think I'd want to understand better before raising an issue.
user=> (defmulti foo :dispatch)
#'user/foo
user=> (defmethod foo :default [& xs] xs)
#object[clojure.lang.MultiFn 0x35636217 "clojure.lang.MultiFn@35636217"]
user=> (foo 1)
(1)
user=> (foo 1 2)
(1 2)
user=> (foo 1 2 3)
Execution error (ArityException) at user/eval148 (REPL:1).
Wrong number of args (3) passed to: :dispatch
I expect it would be very weird (and maybe not on purpose) for defmethods on a defmulti to have different arities?
so yes, the receiver function must have arity compatibility with the dispatch function
so we might as well lint it as if the dispatch function is called on the args directly
Here's a stab at it: https://github.com/clj-kondo/clj-kondo/discussions/2002 Any folks with insights/interest are most welcome to join in the discussion.
I'm getting an UnsupportedClassVersionError
when using doing npx shadow-cljs watch app
for the first time. I have OpenJDK 8 installed. It says com/google/javascript/jscomp/CompilerOptions has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
. Version 55 is Java 11. I'm on a system where the JDK is managed and I'm trying not to circumvent that because it will lead to pain. Is there anything I can do? I could point the link /usr/local/bin
to something else but that is inconvenient.
@gerome.bochmann the closure compiler requires java11, so java8 is no longer supported.
Why does it say “`not a constructor`”? They are doing the same in JS var picker *=*
*new* Pikaday({ field*:* $('#datepicker')[0] });
Is it not the same thing?
@maris.orbidans again it depends on where they got Pikaday
from. consult the JS docs on what they used. either import or require