Fork me on GitHub
#calva
<
2021-01-05
>
roelof13:01:48

How can I step by step through a code to see what I really does ?

pez13:01:30

You mean like in a debugger?

roelof13:01:13

I think so

roelof14:01:13

or did I type the break on the wrong place

roelof14:01:18

(defn validate2
  [validators suspect] #break
  (reduce-kv (fn[acc k v]
               (and acc                            ;; The previous keys were validated
                    (contains? suspect k)   ;; the suspect contains the key in question
                    (v (suspect k))))            ;; the value of that key in the suspect validates according to the validator function
             true validators)) 

roelof14:01:53

as soon as I choose to got in the code It seems that the debugging stops

pez14:01:12

What I do in cases like that (nice small functions) is that I instrument the whole defn. So instead of that #break, I evaluate the code using the debug instrument command instead of the regular one.

Jakub Holý (HolyJak)14:01:34

I have noticed that JS objects in the cljs REPL (or rather in the source code, when evaluating an expression there) are printed in an unhelpful way, such as (`|` is the cursor position when I press Alt-Enter):

js/firebase | => :shadow.cljs/print-error!
(.app js/firebase) | => #object[K [object Object]]
(Wrapping the result with js->clj does not help either.) Is that a known limitation? Thank you!

pez14:01:33

I certainly recognize it. Happens in typescirpt and javascript as well often. Not sure it is the same case, but what I do in TS is that I call JSON.stringify() on the object.

👍 3
roelof14:01:52

@pez oke back to the docs how to do that

pez14:01:39

Another thing I often do is that i def things in the functions. Doesn’t really help all that much in a reduce, but as a general tool it can be useful.

👍 3
roelof14:01:53

hmm, wierd, I do `crtl+alt+c and then i but no breaks

pez14:01:10

That should instrument the function. So that when you run it, it should break. Doesn’t happen?

roelof14:01:32

but when I did `crtl+alt+c and then holding the crtl-alt keys it worked

roelof14:01:42

nice to see how things are working

roelof14:01:36

Now I understand a lilte how this one is working

(defn maps->csv [coll-of-maps]
  (let [header (-> coll-of-maps first keys)                               ;; we take the keys to use as a csv header 
        to-vals (apply juxt header)                                       ;; a function that will extract the map values in the same order as header
        lines (map (fn[m] (->> m                                          ;; we take m
                              to-vals                                     ;; extract the values
                              (clojure.string/join ", "))) coll-of-maps)  ;; and join them as strings
        header-string (->> header (map name) (clojure.string/join ", "))] ;; header string
    (str header-string "\n" (clojure.string/join "\n" lines))))  

bringe23:01:32

Hi @andyfry01, @yadolghintev388, and @zeiglerr, welcome to the channel 👋simple_smile

afry23:01:58

Thank you!