beginners

Getting started with Clojure/ClojureScript? Welcome! Also try: https://ask.clojure.org. Check out resources at https://gist.github.com/yogthos/be323be0361c589570a6da4ccc85f58f.
zendevil 2020-12-06T03:48:44.019200Z

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

2020-12-06T16:20:32.024900Z

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

Ben Sless 2020-12-06T16:41:09.025200Z

maybe https://github.com/weavejester/hashp

👍 2
Michael W 2020-12-06T18:39:35.026600Z

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

phronmophobic 2020-12-06T18:42:03.027200Z

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

Michael W 2020-12-06T18:42:37.027500Z

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

phronmophobic 2020-12-06T18:43:23.027700Z

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

phronmophobic 2020-12-06T18:44:53.028500Z

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

st3fan 2020-12-06T18:48:23.030300Z

is there a looping variant of the threading macros?

st3fan 2020-12-06T18:49:02.030700Z

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

2020-12-06T18:50:20.031800Z

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.

st3fan 2020-12-06T18:50:44.032200Z

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

2020-12-06T18:51:23.033Z

Something like reduce? Or somehow different than reduce?

dpsutton 2020-12-06T18:51:24.033100Z

not sure how map gets involved. seems more like iterate

st3fan 2020-12-06T18:53:51.034Z

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

st3fan 2020-12-06T18:54:28.034600Z

beginners questions! 😕

2020-12-06T18:54:56.035Z

This is the place for them!

st3fan 2020-12-06T18:56:06.036800Z

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
2020-12-06T18:56:18.037200Z

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.

2020-12-06T18:57:07.037300Z

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

seancorfield 2020-12-06T18:57:20.037600Z

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

phronmophobic 2020-12-06T18:57:39.037900Z

there's also @borkdude’s https://borkdude.github.io/re-find.web/

seancorfield 2020-12-06T18:57:58.038Z

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

seancorfield 2020-12-06T18:58:46.038200Z

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

2020-12-06T18:59:41.038400Z

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

seancorfield 2020-12-06T19:01:25.038700Z

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.

vncz 2020-12-06T20:04:32.038900Z

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

vncz 2020-12-06T20:05:12.039200Z

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

alexmiller 2020-12-06T20:10:51.039500Z

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

Michael W 2020-12-06T20:53:15.039800Z

Damn, that is exactly what I needed. Thanks.

Brandon Olivier 2020-12-06T20:59:51.040700Z

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?

2020-12-07T17:32:18.086100Z

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

😂 1
Brandon Olivier 2020-12-06T21:00:19.040800Z

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

phronmophobic 2020-12-06T21:01:05.041Z

there are also other APIs that expect readers

phronmophobic 2020-12-06T21:01:28.041200Z

especially when writing code that interoperates with java code

seancorfield 2020-12-06T21:04:44.041400Z

@brandon149 slurp calls io/reader on its argument.

seancorfield 2020-12-06T21:06:45.041600Z

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 Olivier 2020-12-06T21:07:11.041800Z

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

st3fan 2020-12-06T22:14:40.042600Z

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

st3fan 2020-12-06T22:15:10.042900Z

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

borkdude 2020-12-06T22:16:07.043200Z

@st3fan You can use doseq + require

st3fan 2020-12-06T22:16:31.043500Z

Inside the ns form?

borkdude 2020-12-06T22:16:34.043700Z

no

st3fan 2020-12-06T22:16:56.043900Z

Ok I’ll give that a try

dpsutton 2020-12-06T22:17:56.044800Z

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

bronsa 2020-12-06T22:17:57.044900Z

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

borkdude 2020-12-06T22:18:15.045400Z

ah yeah, the nested libspecs...

dpsutton 2020-12-06T22:18:32.045800Z

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

borkdude 2020-12-06T22:20:36.046Z

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

dpsutton 2020-12-06T22:21:07.046200Z

oh i missed this was a test ns

dpsutton 2020-12-06T22:21:25.046600Z

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

st3fan 2020-12-06T22:21:49.047200Z

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

borkdude 2020-12-06T22:22:27.047800Z

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

st3fan 2020-12-06T22:22:50.048600Z

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

borkdude 2020-12-06T22:22:51.048700Z

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

dpsutton 2020-12-06T22:23:23.049200Z

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

borkdude 2020-12-06T22:23:36.049600Z

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

st3fan 2020-12-06T22:23:42.049800Z

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

st3fan 2020-12-06T22:24:02.050100Z

i thought all numbers were forbidden

borkdude 2020-12-06T22:24:14.050500Z

numbers are forbidden as the first char in a symbol

st3fan 2020-12-06T22:27:27.052200Z

How is this not a babashka script 😆

borkdude 2020-12-06T22:27:35.052600Z

Pre-babashka ;)

dpsutton 2020-12-06T22:27:49.052900Z

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

st3fan 2020-12-06T22:28:08.053200Z

@dpsutton i’m trying hard to ignore that

st3fan 2020-12-06T22:28:16.053500Z

the struggle is real

borkdude 2020-12-06T22:28:31.054Z

btw, I think that script would run with babashka

dpsutton 2020-12-06T22:28:32.054100Z

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

borkdude 2020-12-06T22:28:54.054300Z

I chose d01, d02, etc. https://github.com/borkdude/advent-of-cljc/tree/master/src/aoc/y2018

st3fan 2020-12-06T22:29:21.054600Z

i think there is an ls option to do natural sorting