Fork me on GitHub
#beginners
<
2020-06-13
>
ckrukp02:06:31

👋 I’m here! What’d I miss?

Ian Fernandez02:06:13

May I ask here questions about cljs?

Ian Fernandez02:06:21

I have some functions here, I dunno how to compose in a map like structure....

Ian Fernandez02:06:16

I want to send-image-to-contacts! to work, some tip ?

seancorfield03:06:04

@d.ian.b I'm not entirely clear what you're trying to do, but I suspect that #core-async might be a good place to ask, or #clojurescript ?

Ian Fernandez03:06:38

I want to iterate send-image-to-contact! onto the contacts vector

Ian Fernandez03:06:17

and the send-image-to-contacts! is not working

mister_m04:06:47

does clojure have association lists like common lisp does?

Daniel Tan13:06:50

looks like a reduce concat keys

rickheere14:06:13

Thanks for the replay, I played around with those functions a little but still no luck

Daniel Tan14:06:14

@rickheere (apply merge-with (comp flatten vector) a)

Daniel Tan14:06:29

quite interesting

Daniel Tan14:06:04

(apply merge-with vector a)
{:s "a", :t [[1 2] [5 6]], :l [[3 4] [7 8]]}

delaguardo14:06:34

(apply merge-with concat a)

rickheere14:06:32

Ah, very good. {:s "a", :t (1 2 5 6), :l (3 4 7 8)} is what I get from

(def a '({:s "a"
         :t [1 2]
         :l [3 4]}
        {:t [5 6]
         :l [7 8]}))

(comment
  (apply merge-with (comp flatten vector) a))

Daniel Tan14:06:11

(apply merge-with concat a) +1

rickheere14:06:29

I think that is good enough for now. Thanks @delaguardo and @danieltanfh95!

andy.fingerhut14:06:40

If you care about list versus vector in the result, you can replace concat with your own hand-written function that checks for list vs. vector, etc.

Daniel Tan14:06:28

(apply merge-with (comp vec concat) a) works as well

rickheere14:06:17

I managed to get it to work with this as well

(apply merge-with (fn 
                      [a b] 
                      (into [] (concat a b))) a)

rickheere14:06:55

and yes (apply merge-with (comp vec concat) a) also work, probably better.

rickheere14:06:00

Thanks everyone.

mister_m20:06:09

Does anyone have an idiomatic way to test if a vector is sorted? I've got a predicate using destructuring and recur and I don't like it very much.

dpsutton20:06:44

depending on the size you could just do (= c (sort c)) where c is your vector or collection

seancorfield20:06:26

@radicalmatt If all the items in the vector are numbers, I guess you could also try (apply <= c)?

👍 1
sveri20:06:42

@dpsutton That was my first thought too, but, then you can just sort the vector and know that it's sorted, saving an equals on the whole vec

andy.fingerhut20:06:55

If the true / false test of a <= b is some other function cmp, then something like (every? (map cmp (partition 2 1 coll))) would work

sveri20:06:23

If it comes from outside your application I would say you have to sort it yourself to be sure. If it's your own code, maybe it's possible to write some static analysis?

andy.fingerhut20:06:45

Not at a repl to test that right now — it is probably at least slightly wrong

dpsutton20:06:54

the test of a collection being sorted does not require sorting it to be sure

mister_m20:06:03

wow how did I miss apply

mister_m20:06:16

sean strikes again

bartuka20:06:17

I would probably do something like this to verify if not sorted, then resume

(reduce
 (fn [acc v]
   (if (<= acc v)
     v
     (reduced false)))
 a)

mister_m21:06:44

hm I didn't know about reduced either

athomasoriginal21:06:51

What’s a good approach for printing the stack frames of a function call in Clojure? I would like to see the entire stack trace including the 3rd party libraries that my function is calling.

seancorfield21:06:00

@tkjone At any given point you can try & catch an exception and get the stack elements from the exception object: there's a function Throwable->map in Clojure that will turn the object into Clojure data.

seancorfield21:06:56

But you can only get at the stack from where you are in the call tree -- you wouldn't able to see down into 3rd party code below your current execution point.

athomasoriginal21:06:03

kind of like of you can do this with console.trace in cljs/js

seancorfield21:06:23

@tkjone You may find https://github.com/clojure/tools.trace/ helpful for that (as long as the 3rd party libs are all Clojure).