Fork me on GitHub
#beginners
<
2020-12-06
>
prit03:12:44

Is there a point cloud library or an open 3d alternative for clojure?

Stuart16:12:32

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))
????

Stuart18:12:07

That looks exactly what I'm after, thank you!

seancorfield18:12:20

(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')

seancorfield18:12:58

Ah, you want for ->> -- sorry, yeah, that's a little harder.

seancorfield18:12:46

You could do (->> ... (#(doto % (println))) ...) but that's a big uglier than you might want inline.

Stuart18:12:41

maybe best solution is just to #_ the linse below, evaluate and see the result :slightly_smiling_face:

seancorfield19:12:25

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.

Michael W18:12:35

In a map across a collection of numbers, is it possible to bring the previous and next collection items into the map function?

phronmophobic18:12:03

a common trick is to do: (map f coll (next coll) (nnext coll))

Michael W18:12:37

Oh that looks handy, let me play with that, thanks.

phronmophobic18:12:23

this will only give you elements where there is a next and next next

phronmophobic18:12:53

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

alexmiller20:12:51

you can also use (partition 2 1 coll) to make pairs of adjacent elements

Michael W20:12:15

Damn, that is exactly what I needed. Thanks.

st3fan18:12:23

is there a looping variant of the threading macros?

st3fan18:12:02

apply a thread of operations to a value, feeding it the value and an additional argument from a seq

andy.fingerhut18:12:20

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.

st3fan18:12:44

i want to feed the result of the previous map function into the next map function

andy.fingerhut18:12:23

Something like reduce? Or somehow different than reduce?

dpsutton18:12:24

not sure how map gets involved. seems more like iterate

st3fan18:12:51

hmm i was going to say iterate with an additional coll argument, but I guess that is basically reduce then

st3fan18:12:28

beginners questions! 😕

andy.fingerhut18:12:56

This is the place for them!

st3fan18:12:06

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

😄 1
vncz20:12:32

@st3fan I am also trying to solve Advent of Code with Clojure! https://github.com/XVincentX/aoc2020

vncz20:12:12

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

andy.fingerhut18:12:18

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.

Brandon Olivier20:12:51

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?

Brandon Olivier21:12:19

I should’ve used the Clojure vocab word “rationale”

phronmophobic21:12:05

there are also other APIs that expect readers

phronmophobic21:12:28

especially when writing code that interoperates with java code

seancorfield21:12:44

@UJL94RYSW slurp calls io/reader on its argument.

seancorfield21:12:45

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.

Brandon Olivier21:12:11

I think I understand. I’ve also got this a little backwards between slurp and reader, in that case.

noisesmith17:12:18

slurp is not "raw", it is extremely "cooked"

😂 1
st3fan22:12:40

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]))

st3fan22:12:10

Can’t do advent-of-code.* right?

borkdude22:12:07

@st3fan You can use doseq + require

st3fan22:12:31

Inside the ns form?

st3fan22:12:56

Ok I’ll give that a try

dpsutton22:12:56

presumably you're reading something from std-in for which "day" to run?

bronsa22:12:57

in ns you caould also do [advent-of-code [day1 :as day1] [day2 :as day2] ..]

borkdude22:12:15

ah yeah, the nested libspecs...

dpsutton22:12:32

assuming there's some input dictating which function to run, i'd probably look at requiring-resolve

borkdude22:12:36

(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)))

dpsutton22:12:07

oh i missed this was a test ns

dpsutton22:12:25

oh. why the main ns anyways? most test runners look for tests anyways. no need for this central ns

st3fan22:12:49

I can just require the right thing in my deftest maybe that is even simpler

borkdude22:12:27

In "normal" projects, you usually make a test ns for each ns under test

st3fan22:12:50

yeah i guess i can do that but that is still 25 requires 🙂

borkdude22:12:51

and then you can run it with lein :test :only foo.bar-tests or clojure -M:test -n foo.bar-tests

dpsutton22:12:23

its advent of code. just put the tests in the same ns

borkdude22:12:36

well, the way I usually solve this is copy paste a template ns, throw some scripting at it

st3fan22:12:42

Also, I was surprised that this did not result in any warnings or errors advent-of-code.2015.1

st3fan22:12:02

i thought all numbers were forbidden

borkdude22:12:14

numbers are forbidden as the first char in a symbol

st3fan22:12:27

How is this not a babashka script 😆

borkdude22:12:35

Pre-babashka ;)

dpsutton22:12:49

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

st3fan22:12:08

@dpsutton i’m trying hard to ignore that

st3fan22:12:16

the struggle is real

borkdude22:12:31

btw, I think that script would run with babashka

dpsutton22:12:32

haha it always bugged me in the past. hate seeing day 11, day 12, day 13 .... day 1, day 2, day 20

st3fan22:12:21

i think there is an ls option to do natural sorting