This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-07-08
Channels
- # announcements (2)
- # babashka (100)
- # beginners (25)
- # biff (7)
- # calva (13)
- # cider (24)
- # clj-kondo (39)
- # cljsrn (2)
- # clojure (22)
- # clojure-dev (13)
- # clojure-europe (12)
- # clojure-gamedev (3)
- # clojure-losangeles (2)
- # clojure-nl (1)
- # clojure-norway (3)
- # clojure-spec (11)
- # clojure-uk (2)
- # clojurescript (20)
- # core-async (8)
- # cursive (7)
- # data-science (2)
- # datomic (14)
- # emacs (6)
- # events (7)
- # fulcro (9)
- # honeysql (1)
- # kaocha (24)
- # lambdaisland (3)
- # leiningen (6)
- # lsp (30)
- # membrane (7)
- # missionary (10)
- # nbb (48)
- # nextjournal (13)
- # off-topic (6)
- # parinfer (4)
- # pathom (1)
- # polylith (1)
- # reagent (7)
- # rewrite-clj (6)
- # ring (11)
- # sci (7)
- # shadow-cljs (8)
- # sql (13)
I think I've found a bug in clojure 1.11. No minimal repro yet, but this is a repro, it worked under 1.10:
(def flatten
"A transducer version of clojure.core/flatten"
(fn [rf]
(fn
([] (rf))
([result] (rf result))
([result input]
(if (sequential? input)
(transduce flatten rf result input)
(rf result input))))))
(into [] flatten [[1] [2] [3]]) ;; => boom
I would guess it's https://clojure.atlassian.net/browse/CLJ-2556 ?
Execution error (ClassCastException) at user/flatten$fn (REPL:10).
class clojure.lang.PersistentVector cannot be cast to class clojure.lang.ITransientCollection (clojure.lang.PersistentVector and clojure.lang.ITransientCollection are in unnamed module of loader 'app')
Switching impl to this seems to fix it:
(def flatten
"A transducer version of clojure.core/flatten"
(fn [rf]
(fn
([] (rf))
([result] (rf result))
([result input]
(if (sequential? input)
(reduce (flatten rf) result input)
(rf result input))))))
there were some changes in into completion
I'm not sure your code is right wrt reduced
if the inner reduce returns a reduced, you need to wrap in a second reduced (see cat
impl)
You're right, I think that's broken. But I don't think that's the problem in this case.
into
didn't introduce a reduced
. I think the problem is that there's now an official completion which calls persistent
. And by using rf
with transduce we are completing earlier than expected now.
yeah, I think that makes sense based on the exception
(def flatten
"A transducer version of clojure.core/flatten"
(fn [rf]
(fn
([] (rf))
([result] (rf result))
([result input]
(if (sequential? input)
(transduce flatten (completing rf) result input)
(rf result input))))))
Does the trick. But tbh, I think my original decision to just turn it into an rf and use reduce
is probably more correct now I understand it. We are trying to recursively reduce. We just got lucky that the completion has done nothing in context up until now.