This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-12-25
Channels
- # adventofcode (5)
- # announcements (2)
- # babashka (10)
- # beginners (25)
- # calva (2)
- # clojure (23)
- # clojure-europe (1)
- # clojure-nl (3)
- # clojure-uk (5)
- # clojurescript (6)
- # community-development (5)
- # core-async (16)
- # core-logic (17)
- # datomic (9)
- # defnpodcast (1)
- # duct (6)
- # emacs (4)
- # leiningen (3)
- # off-topic (99)
- # planck (1)
- # shadow-cljs (3)
- # sql (1)
- # tools-deps (6)
- # vrac (2)
Am I right that (transduce indentity f xs)
is equivalent to (f (reduce f (f) xs))
?
Working on advent of code, day 23. I created a bunch of input and output channels, so channels
is of the shape {addr {:in-chan <channel> :out-chan <channel>}}
, and then I have this router block, which i'm running in the repl over cider.
(let [channels (zipmap (range 50)
(repeatedly (fn [] {:in-chan (a/chan 10) :out-chan (a/chan 10)})))]
;; Boot all computers
(doseq [[addr {:keys [in-chan out-chan] :as inout}] channels]
(intcode-computer inout addr))
;; Do routing
(while true
(let [[msg _] (a/alts!! (map :out-chan (vals channels)))
[addr x y] msg]
(println "msg" msg)
(if (= addr 255)
(do (close-all channels)
(println "=================================>>>" y))
(do
(println "routed" [x y] "to" addr)
(a/onto-chan
(get-in channels [addr :in-chan])
[x y]
false))))))
I'm pretty sure that :out-chan
s are being written to, in go
blocks with >!
(I'm writing a vector to the :out-chan
s)
but somehow alts!!
doesn't seem to ever return; the println "rrrrrrrrrrrrrrrrrrr"
never executes.
Can someone help me out? Why doesn't the println execute?ah yes haha but the output is in the form [addr x y]
while the next input is x
then y
so it was not direct to use pub and sub. i could try that, though.
are you also working on AOC?
so it seems like if I send a message in every iteration within the intcode-computer
it works, but if i don't, something locks up
I figured alts!!
isn't what i want since i'm not sure what happens to the other messages on the channel when one of them resolves, so i switched the implementation
(let [channels (zipmap (range 50)
(repeatedly (fn [] {:in-chan (a/chan 100) :out-chan (a/chan 100)})))]
;; Boot all computers
(doseq [[addr {:keys [in-chan out-chan] :as inout}] channels]
(intcode-computer inout addr))
;; Do routing
(while true
(let [[addr x y] (a/<!! (a/merge (mapv :out-chan (vals channels))))]
(println "msg" [addr x y])
(if (= addr 255)
(do (close-all channels)
(println "=================================>>>" y))
(do
(println "routed" [x y] "to" addr)
(a/onto-chan
(get-in channels [addr :in-chan])
[x y]
false))))))
They were talking about the conj function on #clojure earlier. Can be seen here: https://stackoverflow.com/questions/59463747/how-does-clojure-bind-variable-parameters/59465336#59465336 Why if fn being used in the def's body (seems it can be removed without messing anything up)? Is it because of the :static metadata?
I just finished watching @ericnormand 's excellent "REPL Driven Development" course in https://purelyfunctional.tv/. I really recommend to purchase that course if you are learning Clojure or you want to learn more productive REPL driven development practices as I did. I'm not a complete newbie in Clojure but I must say that I learned a lot watching a seasoned Clojurian working with the code and REPL and explaining what he was doing and why. That is definitely something you cannot learn just by reading Clojure books.
He uses mostly Emacs + Cider and is very fluent with that tool. But he occasionally also uses IntelliJ IDEA + Cursive. But the editor is not the main point, not at all. He demonstrates good REPL practices that you can use what ever editor you choose to use.
Another great resource is Stuart Halloway's Repl Driven Development presentation. I started immediately using a repl scratch file to edit my repl experiments instead of using the repl editor. https://vimeo.com/223309989
Would you say http://PurelyFunctional.tv would be suited for someone that's a total Clojure newbie?
Anyone knows a good book or course about topic "Clojure standard library hidden gems"? 🙂
I just go to http://clojuredocs.org and peruse all the stuff in clojure.core
. You could read the docstrings straight from your REPL but, there are crowd-sourced examples for these things on that site that I find very useful.
That, and looking at other people's solutions on 4clojure also taught me a lot of interesting ways in which the core fns compose together.
@kari.marttila This perhaps? https://www.manning.com/books/clojure-the-essential-reference
Yes! Definitely going to buy that Clojure book as well!