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?

seancorfield04:06:56

@radicalmatt Clojure has first class associative data structures: hash maps.

Jim Newton08:06:56

is there a standard clojure documentation system which I should use if I'd like to release a library to the public?

practicalli-johnny17:06:29

@U010VP3UY9X http://cljdoc.org will use the docstrings from your function definitions, eg. (defn name "docstring explaining the function" [] (algoritym)) . Also README and CHANGELOG files. https://github.com/cljdoc/cljdoc/blob/master/doc/userguide/for-library-authors.adoc

Jim Newton07:06:07

I don't understand about the CHANGELOG. Am I responsible for physically updating the file, or is it something that happens automatically according to certain reserved words in git commit messages? or do I need to create git tags for important commits?

Jim Newton07:06:04

I'm using my schools local installation of gitlab which has an issue tracker. Is there a way for me to make issues and associate their fixes with certain commits, and have the changelog assembled from that information?

practicalli-johnny13:06:36

A changelog is usually update manually, and adding links to the most relevant issues or pull requests to include. You may find tools that help with creating a changelog, but I see the changelog as a summary of activities. All the details are in the issue tracker, commits and pr's, so the changelog helps humans understand if something important to them has changed.

rickheere13:06:53

How do I transform this?:

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

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

👍 4
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

sveri20:06:05

Yea, thats true and finding out it's not sorted is probably faster than sorting it.

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:44

Thanks, Sean! So the only way to trace, for example, a 3rd party library, I would have to clone said library and run the trace through that library. In general, i’m researching how a library works and I want to see all the function calls being made to get a high level overview of the code paths.

athomasoriginal14:06:45

Thanks! I will give this a try 🙂

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