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))
????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))
Oh that looks handy, let me play with that, thanks.
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
is there a looping variant of the threading macros?
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.
i want to feed the result of the previous map function into the next map function
Something like reduce
? Or somehow different than reduce
?
not sure how map gets involved. seems more like iterate
hmm i was going to say iterate
with an additional coll
argument, but I guess that is basically reduce
then
beginners questions! 😕
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
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.
That looks exactly what I'm after, thank you!
(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')
there's also @borkdude’s https://borkdude.github.io/re-find.web/
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.
@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
you can also use (partition 2 1 coll)
to make pairs of adjacent elements
Damn, that is exactly what I needed. Thanks.
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?
slurp is not "raw", it is extremely "cooked"
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
@brandon149 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]))
Can’t do advent-of-code.*
right?
@st3fan You can use doseq
+ require
Inside the ns
form?
no
Ok I’ll give that a try
presumably you're reading something from std-in for which "day" to run?
in ns
you caould also do [advent-of-code [day1 :as day1] [day2 :as day2] ..]
ah yeah, the nested libspecs...
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 i missed this was a test ns
oh. why the main ns anyways? most test runners look for tests anyways. no need for this central ns
I can just require the right thing in my deftest
maybe that is even simpler
In "normal" projects, you usually make a test ns for each ns under test
yeah i guess i can do that but that is still 25 requires 🙂
and then you can run it with lein :test :only foo.bar-tests
or clojure -M:test -n foo.bar-tests
its advent of code. just put the tests in the same ns
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
i thought all numbers were forbidden
numbers are forbidden as the first char in a symbol
@st3fan https://github.com/borkdude/advent-of-cljc/blob/master/script/new
and https://github.com/borkdude/advent-of-cljc/blob/master/test/aoc/new.clj
How is this not a babashka script 😆
Pre-babashka ;)
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
@dpsutton i’m trying hard to ignore that
the struggle is real
btw, I think that script would run with babashka
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
i think there is an ls
option to do natural sorting