This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-12-07
Channels
- # adventofcode (40)
- # aws (15)
- # babashka (76)
- # beginners (39)
- # calva (6)
- # cider (3)
- # clj-kondo (3)
- # clojure (89)
- # clojure-austin (1)
- # clojure-australia (4)
- # clojure-europe (42)
- # clojure-italy (9)
- # clojure-nl (27)
- # clojure-spec (8)
- # clojure-uk (17)
- # clojurescript (9)
- # conjure (1)
- # data-science (1)
- # datomic (19)
- # deps-new (4)
- # docker (9)
- # emacs (5)
- # events (1)
- # fulcro (36)
- # kaocha (31)
- # lambdaisland (5)
- # leiningen (3)
- # membrane (3)
- # nrepl (10)
- # off-topic (31)
- # pedestal (7)
- # reveal (47)
- # shadow-cljs (35)
- # sql (9)
- # test-check (1)
- # tools-deps (24)
- # uncomplicate (12)
- # xtdb (5)
Good morning 🙂
“Oh oh oh” (to read with the voice of Santa Claus) … it seems that the channel is more quiet than usual 😉
might because it’s Monday 😁
Today's was definitely harder than the last few days, but not too hard yet. I quite like them like this. A bit challenging but still solvable in under an hour.
Under an hour you say? 😛
I’m lucky I still have time for breakfast
I am going to add Specter and Instaparse to my deps.edn
I’m going to stack with vanilla Clojure for this AoC
yeah I'm also generally sticking to vanilla clojure, unless I really end up re-implementing a common library
and solution: https://github.com/lambdaisland/aoc_2020/blob/main/src/lambdaisland/aoc_2020/puzzle07.clj I also talk a bit more about yesterday's puzzle, and answer some questions people asked in the comments.
maybe I missed it, have you mentioned that using io/reader
without with-open
macro is not a good practice?
curious to what’s wrong? :_
have to stay tuned I guess
find out tomorrow in a new episode
I think its because if you call io/reader
without with-open
(or explicitly try / catch yourself), then you can be left with an open reader in the case of an exception? But I'm guessing here. If thereis an exception I think with-open
calls close on its binding
Somehow I managed a stack overflow using loop
/`recur` :man-shrugging:
(count (bag-children "shiny gold" sample-bags))
=> 32
(count (bag-children "shiny gold" bags))
Execution error (StackOverflowError) at (REPL:1).
Can anyone help me figure out my stack overflow issue? I realize my code/approach is far from optimal… all the same it bugs me I can’t reason about why this is failing the way it is https://gist.github.com/KennyMonster/4e965505f0a8b592a91dd25b5306023f
(defn bag-children [color bags]
(let [bags-lookup (into {} (map #(vector (:color %) %) bags))]
(loop [colors-to-walk [color]
bag-children []]
(if (seq colors-to-walk)
(let [contained-bags (mapcat contained-bag-colors-as-seq (:contain (bags-lookup (first colors-to-walk))))]
(recur (into (subvec colors-to-walk 1) contained-bags)
(into bag-children contained-bags)))
bag-children))))
it is lazy, which is why you're getting the stack overflow. consider this
(def x (reduce concat (map #(list %) (range 100000))))
(first x)
the def
will work fine, but as soon as you try to realize the first element it throws. At that point it tries to realize the outer concat
, which first needs to realize the concat
inside of it, and so forth until it bottoms out. Realizing a lazy-seq concumes a stack frame. It's really just a wrapper around an IFn
which implements the Seq interface.