Fork me on GitHub

Is there a way to automatically format my clojure code in emacs? Like something that includes a prettifier that squashes all the trailing parenthesis to a single line automatically?

Vincent Cantin09:05:20

I have a question about the conventions in Clojure .. predicates’s names are often ended with a ? . Should we also use a ? for hash-map keys (keywords) referring to boolean values? e.g. :valid? instead of :valid

Michaël Salihi12:05:19

Good question whose answer interests me too. I think so, from what we can observe on some libraries like ring-jetty-adapter for example:


I think it's less important with map keys. The reason it is a convention for procedure calls is that it informs you that you are returning a boolean, but with a map key, you will see a default value of true/false right next to it. Don't let that stop you from doing it if that's how you like it though. It definitely doesn't hurt. 🙂

👍 4

@pshar10, if in emacs/spacemacs just highlight code and then press tab - it formats; if in vsc then press Ctl-shift-P and select beautify (if not found you need to add the add-on)


in spacemacs that just indents it. I mean making: ((( code... ) ) ) to (((code ... )))


a common trick is to use smartparens (or paredit, etc) to clean up as you go. for example, hitting ")" to close the sexp causes the parentheses to gather on the same line.


I do have paredit mode on on spacemacs but that doesn’t automatically gather them?


I may be mistaken about paredit -- I thought it behaved the same but it's been a while since I switched to smartparens. (the example above is smartparens with sp-autoskip-closing-pair set to 'always)


(def d1 [{:key "document_env", :value "teste"} {:key "document_env2", :value "teste2"}])


@tvalerio @andy.fingerhut an alternative is (flatten (map vals d1)) results in ("document_env" "teste" "document_env2" "teste2"); it is equivalent, no?


That is a list of 4 strings. The questioner was asking how to get a result that was a map with 2 key/value pairs, which is a different result.


I want to ask an open question about macros to seasoned clojurians. What do you use macros for in your projects? Can you give an example where you used a macro and were like, "holy shit, this makes life so much better." Would you please share it?


Hi. I'm not a beginner but I'd like to know what's the recommended way to go with ClojureScript these days. Figwheel ? Shadow-cljs ?


I don't practice ClojureScript often enough to know which one I should pick.


Shadow-cljs is quite easy to get started with, but if you start a new CLJS project using a leiningen template, then figwheel is usually set up for you too. One advantage of shadow-cljs is that it's more of an all-in-one tool, so if you're only doing basic CLJS then you only need this.


Hi all! Just a short question: Is there any way to register spec definitions (`s/def` ) with dynamic keywords?


I saw it will be possible in spec 2 with s/register , but I wonder if there is a solution to this in spec 1


I found a solution through spec-tools.impl/register-spec!


Hi. 🖐️ anyone knows if this website is maintained/updated ?


it’s definitely being updated (I had a library added not too long ago). afaik, it’s being updated via pull requests that anyone can submit, but I’m not sure it’s curated in the sense that I don’t think libraries get removed or are actively searched for by the maintainer.


it’s possible that it’s being actively maintained, but I’m not sure.


it’s worth noting that it’s common for clojure libraries to go years without changes and still work well in the present. it’s one of the benefits of clojure that clojure code bitrots much more slowly than other ecosystems


I agree about your last point but for newbies like me we get a little bit confused :) in fact I was searching for ‘etoin’ alternatives but didn’t found any place to search.


as a newbie I spend lots of time “”Yak shaving”” libs


i’ve never thought about how other people evaluate libraries


i’ve also never heard of etoin


I don’t have yet the proper/deep knowledge to eval if I am using the correct lib for some task :( sometimes it’s frustrating


I don’t feel like I have issues evaluating libraries, but it’s also possible that I’ve only gotten marginally better and have just gotten used to it


Like libs for ArangoDB. All look pretty outdated regarding their features and API versioning


Yes maybe you rock in clojure :)


I also have a background with java and javascript, so it’s nice to be able to add java and javascript libraries to the list that I might be comfortable with, but I could see how that might be annoying for developers who are looking at clj and cljs as a way to avoid learning the dumb quirks and trivialities of js and java


i’m usually pretty wary of libraries that try to do too much on top of wrapping java/javascript libraries


for something like arangodb, I would probably prefer using the java library directly unless there’s a clj wrapper library that looks like a really good fit


So in that case do you prefer to just go with the java lib version and use interop?


I was writing my question before reading your reply :) nice nice I kind like your reply


I will follow your tip! :)


an example of a library that adds a lot of value compared to using java library is carmine (a redis client lib).


Let me check


since the redis protocol has a you don’t really have to worry about it not supporting some feature


cool distributed lock also 🙂


I see. you can just work with that data structure

Scott Starkey22:05:03

OK, I’m learning about the threading macros, and I’m wanting to thread a state through the following transformations:

(my-function state 0)
(my-function state 0)
(my-function state 0)
(my-function state 0)
(my-function state 1)
(my-function state 1)
(my-function state 1)
(my-function state 1)
… and then get the state out the other side. Can someone please help me with the idiomatic way of doing this?


@scotto Your function returns the new state each time?


If so, (-> state (my-function 0) (my-function 0) ... (my-function 1) (my-function 1))

Scott Starkey22:05:17

That’s what I thought, but it failed for some reason in practice. Lemme try it again.


If your calls really are to the same function every time, just with different arguments after the state, I'd probably use reduce instead.


(reduce (fn [state data] (my-function state data)) state collection-of-data-values)

👍 4

Why (fn [state data] (my-function state data) , why not just pass my-function directly to reduce ?


@UTQEPUEH4 In this case, yes, that works. I was trying to show the shape of the (my-function state 0) style calls (and also in the back of my mind thinking of a general case where my-function actually took more than two arguments and you might need (apply my-function state data) with collection-of-data-values being collection-of-collection-of-argument-values 🙂 ).