Fork me on GitHub
#beginners
<
2021-06-11
>
Endre Bakken Stovner05:06:24

@manutter51 @noisesmith Thanks! I will test out your suggestions later today. It should also be said that I run the code that calls tap> in a Thread. which might add another layer of weirdness. Here is the whole function:

(defn read-process [proc type jobid] ;; babashka/process
  (with-open [rdr (io/reader (type proc))]
    (binding [*in* rdr]
      (loop []
        (let [line (read-line)]
          (when (not (nil? line))
            (tap> [jobid type line])
            (recur)))))))
Here is how it is called:
(.start (Thread. #(read-process bb-process :err jobid)))
(.start (Thread. #(read-process bb-process :out jobid)))

popeye06:06:31

I am practising clojure program where I have 2 variable like below

(def  map1 [{:color "Orange" :size 8} {:color "blue" :size 9}] )
(def  map2 [{:size 8 :color "Orange" } {:color "yellow" :size 10} {:color "blue" :size 9}]) 
if any element of map 2 exist in map1 then store in some variable else store in other variable, I have checked with diff and compare did helped me, how can I write best program

dpsutton06:06:51

(set/intersection (set map1) (set map2))

popeye06:06:26

wow!!! how to get unmatched map ?

popeye06:06:04

Also will this be a costly operation if we have n number of maps inside it?

Jacob Rosenzweig07:06:18

What does @conn in this context:

(def cfg ...)
(def conn (d/connect cfg))
...
(some-function @conn)

Jonas-Daima07:06:25

@ is a https://clojure.org/reference/reader#_deref for deref, so it is just that. As a side note, database connections are usually put in a delay, which requires deref. To ensure the connection is only created when explicitly asked for.

Jacob Rosenzweig07:06:31

Does it reevaluate the var?

Jacob Rosenzweig07:06:09

Oh it's a deref?

noisesmith15:06:47

quote is often helpful - it reveals what the reader expands without evaluating:

user=> '@foo
(clojure.core/deref foo)

noisesmith15:06:41

it even reveals itself 😄

user=> ''foo
(quote foo)

noisesmith15:06:02

etc.

user=> '#(+ % %)
(fn* [p1__159#] (+ p1__159# p1__159#))

Jacob Rosenzweig17:06:37

@noisesmith oh nice. I was doing (type foo) but this seems to tell me more.

noisesmith17:06:44

it's not always useful, but it's easy to try and informative when it works

noisesmith17:06:13

and learning why it works is a big step forward in deep understanding of clojure

popeye07:06:06

Hi, I am trying to update a key in the map

(update {} :match (conj item)  )
returning (:match nil) how can I update key by adding new values, I am using this function in reduce

indy08:06:28

(update {} :match conj item)
No parens around (conj item)

popeye08:06:19

this also worked for me `

(assoc acc :match (conj (get acc :match ) item))

popeye08:06:07

but agree to update

popeye11:06:51

I have a function, which is taking more than 3 minutes complete its operation due to huge data and it is expected, So I am planning to write it in multi threading application, any suggestion ?

indy11:06:38

• What does the data look like? • What does the function do?

popeye11:06:10

I have 2 map which each has more than 100000 map again, I am comparing with another map

indy11:06:04

Don’t quite understand. You mean you have two vectors/lists/sets v1 and v2 which have 100000 hash-maps inside each? And you’re trying to compare v1[i] to v2[i]?

popeye11:06:17

yes, checking element in one map is present in other or not

indy12:06:43

This can be parallelised, you can try pmap for a start. (pmap your-diff-fn v1 v2).

ahungry04:06:09

I think your v2 should be a btree so your O is logarithmic not n*n