This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-04-03
Channels
- # announcements (5)
- # babashka (8)
- # beginners (98)
- # biff (2)
- # calva (20)
- # cider (16)
- # clerk (2)
- # clj-kondo (20)
- # cljdoc (19)
- # clojure (90)
- # clojure-art (3)
- # clojure-boston (1)
- # clojure-europe (7)
- # clojure-nl (2)
- # clojure-norway (47)
- # clojure-uk (3)
- # clojurescript (10)
- # cursive (10)
- # data-science (1)
- # datalevin (1)
- # defnpodcast (1)
- # events (2)
- # fulcro (11)
- # gratitude (2)
- # honeysql (18)
- # hyperfiddle (11)
- # introduce-yourself (1)
- # jobs (2)
- # lambdaisland (4)
- # lsp (6)
- # malli (4)
- # membrane (3)
- # off-topic (58)
- # polylith (14)
- # portal (2)
- # releases (2)
- # ring-swagger (4)
- # tools-deps (8)
- # xtdb (8)
I just wrote this piece of Java-interop:
(defn map->Headers [headers]
(let [headers-obj ^Headers (Headers.)]
(for [[k v] headers]
(->> (cond-> v
(not (coll? v)) vector)
(map str)
(.add headers-obj (name k))))
headers-obj))
After some struggling I realized that the for
here of course does nothing (mutability hurts my brain...). I had to replace it with a doseq
. This pattern - a for
outside of a let
that has forms after it will probably not do what the user intended. An idea for a linting rule?The amount of times I've been bit by a lazy for evaluating just fine in my repl, but not running at all in code, is too damn high!
something like this? feel free to upvote it: https://github.com/clj-kondo/clj-kondo/issues/1757
Actually the middle thing here is reported as an unused value:
$ clj -M:clj-kondo/dev --lint - <<< '(defn foo [] (map inc [1 2 3]) (map inc [1 2 3]))'
<stdin>:1:14: warning: Unused value
but given that your function returns a lazy value you can't reliably say that it will never be executed
The linked idea is also good, but not my exact case. My code simply does not do anything, as it has a lazy form in "the middle position".
ok, I think the case is similar though, the for thing should be reported as an unused value
If it was, then that would be good. Do you mean to say this should already be happening?
it probably should, but isn't working yet as this is a more advanced case, since it's inside of of a let and not on the top level of a function body
I cracked up reading the issue https://github.com/clj-kondo/clj-kondo/issues/2310 where @alexmiller wrote: "Describe alternatives you've considered: Considering changes in Clojure core." Maybe the only person capable of writing such a line.

I filed one PR for this that I saw in the wild https://github.com/funcool/promesa/pull/152 Think I also found a case in Datomic :)
it may be less widespread than I initially thought, several other regression tests I had were traced to other issues
This is a good change, imo. Catching these things can be hard, so I'm glad y'all are gonna start enforcing it
still on the fence about that in core, hate to cause new errors where none existed before. I'm (currently) using the type hint to determine the user expected overload type in an interop call so we can apply function conversion, but I need to resolve the class to do that check. I was surprised to find these cases where the invalid class was not previously failing.