Fork me on GitHub
#beginners
<
2019-01-24
>
Charlot03:01:19

Weird interaction. Javas Math/abs cannot handle fractions, leading to weird, occasional exceptions.

Charlot03:01:31

Oh well, I can deal with floats

jaihindhreddy-duplicate13:01:29

How do I deploy a clojure function to AWS Lambda without Datomic Ions. Is there a hello world example out there with pack.alpha?

victorb14:01:03

Somehow I ended up with a bit of a pickle. When I run my app (`lein run`) or start the repl, everything works fine. But when doing (clojure.tools.namespace.repl/refresh), I suddenly get No namespace: my.namespace error, even though it can normally find it

victorb14:01:59

removing the :aot key with it's value resolved the issue, but not exactly sure about the reasoning why

Daniel Hines17:01:40

What are some general strategies for dealing with nested sequences? E.g if I want to map/reduce/filter on [[[{:foo :bar}]]]? This is when I reach for transducers, right? Or are there other approaches?

Daniel Hines17:01:05

(And the nesting is important to the data. I can't just flatten)

Braden Shepherdson17:01:53

or the specter library.

borkdude17:01:34

assoc-in, update-in, get-in, etc, yeah

borkdude17:01:46

or clojure.walk if you need to visit each leaf

Daniel Hines18:01:09

Correct me if I'm wrong, but update-in and friends are for applying a transformation to a single node. I want to apply transformations to sequences. Clojure.walk could help - I'll have to revisit that.

dpsutton18:01:04

(update-in [[[1 2 3]]] [0 0] #(mapv inc %)) => [[[2 3 4]]]

dpsutton18:01:16

if its nested, sequences are nodes

Daniel Hines18:01:37

Right, but now I want to do that for every node in the sequence at a particular sequence layer.

hiredman18:01:22

I question the need to preserve the nesting structure

hiredman18:01:11

I imagine the nesting structure represents information you want to preserve, but the actually structure can be done away with to make processing easier as long as you preserve the information

Daniel Hines18:01:00

Yes! And if I could figure out a better way to represent the data, that would be much better.

hiredman18:01:23

that is going to depend a lot on what you need from that information

hiredman18:01:30

but for example:

(mapcat
 (fn [item a]
   (mapcat
    (fn [item b]
      (mapcat
       (fn [item c]
         [(assoc item :a a :b b :c c)])
       item
       (range)))
    item
    (range)))
 [[[{:foo :bar} {:foo :bar}]
   [{:foo :bar} {:foo :bar}]]
  [[{:foo :bar} {:foo :bar}]
   [{:foo :bar} {:foo :bar}]]]
 (range))

hiredman18:01:21

that will result in a flat sequences of maps and all the maps having a, b, and c key which together indicate where they were nested

Daniel Hines18:01:01

Thanks for this.

Daniel Hines18:01:03

Timothy here claims with this sort of pattern matching, there's "only one way" to do things, and it's based on the shape of the data.

hiredman18:01:44

there are a couple of libraries (spectre maybe chief among them) that sort of claim to be a missing tool kit for dealing with deeply nested data, usually maps representing trees.

hiredman18:01:20

I have a hard time seeing the point of these libraries because the first thing I want to do when presented with deeply nested data with a lot of structure is removing the nesting and structure, maybe throwing the nesting away completely, or transforming it in to something more like an in memory database using clojure.set/index

borkdude18:01:09

isn’t that also one of the ideas behind om.next?

arnoha18:01:20

is there a function to simplify the pattern for or where you can return the matched value instead of the predicate true/false value? so as to not have to keep doing (or (if (pred1? n) n) (if (pred2? n) n) ….):

(defn daysDiff [localDateTime1 localDateTime2]
   (try
	(let [numDays (-> localDateTime1 (.until localDateTime2 (ChronoUnit/DAYS)))]
	  (or (if (zero? numDays) numDays) (if (pos? numDays) numDays) 0))
   (catch Exception e)))

john19:01:30

I used to get map fatigue, but after years of banging on maps, the rough edges sort of dissolved away and now I no longer feel the pain. I'm usually able to think through the transformation in a reasonable amount of time these days.

john19:01:25

There's a word for that I think...

dpsutton19:01:48

stockholm syndrome? 🙂

15
john19:01:14

lol close... the one where you can no longer see the problem because you got too used to it.

john19:01:22

more commonly used in tech

dpsutton19:01:25

i guess just acclimation

john19:01:48

it's like "nativist bias" or something like that

john19:01:00

or being biased to what your used to