Fork me on GitHub
Abhi Saxena04:08:08

Hi Everyone, hope you all are doing great. I recently moved to Clojure from Java (couple of days back) and first task on my hand is to write a macro which can restructure the attributes encapsulated under a logging context (cambium.core MDC context). So I don't have to rearrange them in every context. Since I am still gaining familiarity with syntax and all; do you have any suggestions on where should I start. Basically I have to group some attributes under common sections. e.g. event related fields under data etc. thanks in advance.


Generally, the first suggestion for questions like this tends to be: try to write it as a function first, rather than a macro. You might want a macro to provide a little "syntactic sugar" over the function later, but try to write a plain function first.

thanks2 1
Shantanu Kumar06:08:27

@U03TDQ043GA Cambium has a macro with-logging-context to do something similar. Maybe that would be useful? Also, there's #cambium channel for Cambium discussion.

Abhi Saxena17:08:51

@U066J7E2U Hey Shantanu, we are actually using Cambium core for this purpose but with each time I use with-logging-context macro I have to rearrange the attributes as per the schema, I was told by my lead that it's repetitive and you should write a macro to handle this restructuring. Also, I really appreciate the work you are doing in Clojure, I have been through couple of your articles when I started with Clojure and they are great.

quan xing11:08:24

Is there if true dosoming endif not else branch in clojure?

quan xing11:08:08

Oh Yah! I forgot it :hugging_face: thanks.

😀 1

There is also (if condition something), although there is some difference of opinion among Clojurians whether if or when is preferable in that situation, perhaps depending upon whether the something has side effects or not. As far as the language itself is concerned, (if condition something) and (when condition something) are identical, but some people want there to be additional information conveyed by the choice of if or when.


Which of the two is meant to indicate side effects?


The language itself does not distinguish this at all, but if I recall correctly, some people argue that it is preferable to use when when the body performs side effects


Here is probably more discussion and reading material on the subject than most people are likely to want to read:

👍 1

Scary error message?!


Sorry it is class clojure.lang.PersistentList$Primordial cannot be cast to class clojure.lang.IPersistentCollection (clojure.lang.PersistentList$Primordial and clojure.lang.IPersistentCollection are in unnamed module of loader 'app')


persistentlist.primordial is list i think. You're probably doing something like (conj list 1) instead of (conj (list) 1)


i remember seeing a doc on common clojure errors but i can't find it anymore. For those "X cannot be cast to class Y" it's quite useful to know the common clojure interfaces to decrypt those quickly (clojure.lang.IFn, clojure.lang.IPersistentVector, etc)


Yes thanks list seems to be root. I was trying rich4clojure problem-153 which has some very awkward tests where you have to compare sets of sets. I am making some checks to see if more than one of the included sets include false as an element


(map (partial into (list)) (into (list) #{#{(= "true") false} #{:yes :no} #{(class 1) 0} #{(symbol "true") 'false} #{(keyword "yes") ::no} #{(class '1) (int \0)}}))


you don't really ever need to convert sets to lists, most clojure functions will work on collections by calling seq As a note: technically not exactly the same but you could simply do (map seq #{#{(= "true") false} ...})


So far (def lst-sets (map seq #{#{(= "true") false} #{:yes :no} #{(class 1) 0} #{(symbol "true") 'false} #{(keyword "yes") ::no} #{(class '1) (int \0)}})) (defn two+false "Given a sequence of booleans test for two or more false" [bol-seq] (< 1 (reduce (fn [acc bol-seq] (if (= false bol-seq) (inc acc) acc)) 0 (next bol-seq)))) (two+false (map (partial not-any? ; check if each set has any false elements #(= false %)) lst-sets))


Hey guys! I have a question - so I would run lein repl and it would work, but then I tried to check out to a tag, specifically running this command git checkout -f 1.10 and tried to run lein repl or lein run but now it’s giving me this error. What did I do wrong? For context, this is an exercise I’m doing from Eric Normand’s intro to Clojure course Also, I tried opening this with Doom Emacs and tried to run it with Spc + m + ' and then Spc + m + e + b but cider jack in wouldn’t establish a connection. Does anyone have a guide for those using Doom Emacs (I’m admittedly quite new to this as well)

Drew Verlee17:08:21

lein run is trying to read the clojure code and it found something it didn't understand, which is what it says here

Drew Verlee17:08:14

so we would have to look at that introduction_to_clojure/core.clj line 32 to learn more. Or the rest of the stacktrace might give us a hint.


Hey Drew! Eric got back to me and clarified that this is a bug that he has yet to check out. Unfortunately, I have no idea why it’s behaving like this. Fortunately, I was able to go thru the exercises with the repl via terminal, and just added functions that were missing to get to the next step

👍 1
Drew Verlee18:08:41

Glad to hear you got the help you needed.