This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-12-06
Channels
- # adventofcode (109)
- # announcements (6)
- # aws (2)
- # babashka (4)
- # beginners (71)
- # calva (6)
- # cider (14)
- # cljs-dev (1)
- # clojure (110)
- # clojure-australia (1)
- # clojure-europe (14)
- # clojurescript (26)
- # cursive (2)
- # data-science (5)
- # events (1)
- # fulcro (65)
- # lambdaisland (4)
- # leiningen (1)
- # midje (1)
- # mount (2)
- # off-topic (13)
- # pathom (5)
- # reclojure (1)
- # reitit (5)
- # reveal (15)
- # ring-swagger (1)
- # sci (1)
- # shadow-cljs (12)
- # test-check (3)
- # tools-deps (76)
- # xtdb (59)
Is there a point cloud library or an open 3d alternative for clojure?
Is their a way to debug values passed through threading macros, e.g.
(->> (mapcat #(str/split % #"") s)
(into #{})
(count))
And say I want to debug the value between into
and count
Right now I'm doing
(defn debug [d]
(prn d)
d)
And then putting that between lines, but there must be a better way! e.g.
(->> (mapcat #(str/split % #"") s)
(into #{})
(debug)
(count))
????(doto println)
can be helpful here: (-> v (doto (println)))
expands to (doto v (println))
which expands to (something like) (let [v' v] (println v') v')
Ah, you want for ->>
-- sorry, yeah, that's a little harder.
You could do (->> ... (#(doto % (println))) ...)
but that's a big uglier than you might want inline.
maybe best solution is just to #_ the linse below, evaluate and see the result :slightly_smiling_face:
That's probably what I would do, to be honest. With #_
or (comment)
depending on what else I was working on. Mostly I write code inside (comment)
while I'm working and then copy it into an actual function once it works.
In a map across a collection of numbers, is it possible to bring the previous and next collection items into the map function?
a common trick is to do:
(map f coll (next coll) (nnext coll))
this will only give you elements where there is a next and next next
there's a way to also write it so that if there isn't a next, use nil, but I can't remember the shortest way to write that
you can also use (partition 2 1 coll)
to make pairs of adjacent elements
apply a thread of operations to a value, feeding it the value and an additional argument from a seq
Not sure what you are going for, but you can do map
with a function whose body contains a threading macro, and that function will be (lazily) called on each element of a sequence.
Something like reduce
? Or somehow different than reduce
?
hmm i was going to say iterate
with an additional coll
argument, but I guess that is basically reduce
then
This is the place for them!
advent of code has finally given me a reason to explore clojure.core in more detail instead of trying to solve everything with loop/recur
@st3fan I am also trying to solve Advent of Code with Clojure! https://github.com/XVincentX/aoc2020
If your specific issue about the day 6 challenge? Because according to what you said I probably did the same thing: https://github.com/XVincentX/aoc2020/blob/master/src/day6.cljc#L16
If you have an example of the kinds of parameters you'd like to pass to some function, and what results you are hoping to get back, folks can probably do the mental pattern matching to see what existing functions/macros can help get there, if there are any.
What’s the motivation for using io/reader
over a raw slurp? I can understand for bigger files, but is there an advantage for smaller ones?
I should’ve used the Clojure vocab word “rationale”
there are also other APIs that expect readers
especially when writing code that interoperates with java code
@UJL94RYSW slurp
calls io/reader
on its argument.
I would say to use io/reader
directly when you need more control over what happens to the data you read -- slurp
just copies from the reader to a string writer and then returns that as a string.
I think I understand. I’ve also got this a little backwards between slurp and reader, in that case.
Is there a better way to do this .. this is getting a bit ridiculous …
(ns advent-of-code.test
(:require [clojure.test :refer :all]
[advent-of-code.day1 :as day1]
[advent-of-code.day2 :as day2]
[advent-of-code.day3 :as day3]
[advent-of-code.day4 :as day4]
[advent-of-code.day5 :as day5]
[advent-of-code.day6 :as day6]))
assuming there's some input dictating which function to run, i'd probably look at requiring-resolve
(require '[clojure.test :as t])
(defn -main [n]
(let [ns (symbol (str "advent-of-code.day") (Integer/parseInt n))]
(require ns)
(t/run-tests ns)))
oh. why the main ns anyways? most test runners look for tests anyways. no need for this central ns
and then you can run it with lein :test :only foo.bar-tests
or clojure -M:test -n foo.bar-tests
well, the way I usually solve this is copy paste a template ns, throw some scripting at it
Also, I was surprised that this did not result in any warnings or errors advent-of-code.2015.1
and an annoyance i've hit in the past is to use 01
not 1
for the days so they sort correctly once you hit day11 and greater
haha it always bugged me in the past. hate seeing day 11, day 12, day 13 .... day 1, day 2, day 20
I chose d01, d02, etc. https://github.com/borkdude/advent-of-cljc/tree/master/src/aoc/y2018