This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-05-09
Channels
- # babashka (22)
- # beginners (58)
- # calva (14)
- # clj-kondo (3)
- # cljs-dev (4)
- # clojure (17)
- # clojure-dev (4)
- # clojure-italy (6)
- # clojure-uk (2)
- # clojurescript (32)
- # conjure (9)
- # cursive (2)
- # figwheel-main (48)
- # fulcro (77)
- # helix (2)
- # jobs-discuss (3)
- # joker (2)
- # pathom (3)
- # quil (3)
- # re-frame (24)
- # reitit (6)
- # shadow-cljs (11)
- # tools-deps (8)
- # xtdb (29)
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?
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
Good question whose answer interests me too.
I think so, from what we can observe on some libraries like ring-jetty-adapter
for example:
https://github.com/ring-clojure/ring/blob/master/ring-jetty-adapter/src/ring/adapter/jetty.clj#L133-L140
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. 🙂
@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 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?
Good question whose answer interests me too.
I think so, from what we can observe on some libraries like ring-jetty-adapter
for example:
https://github.com/ring-clojure/ring/blob/master/ring-jetty-adapter/src/ring/adapter/jetty.clj#L133-L140
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
Hi. 🖐️ anyone knows if this website is maintained/updated https://www.clojure-toolbox.com/ ?
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.
interesting
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
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
usually
I was writing my question before reading your reply :) nice nice I kind like your reply
an example of a library that adds a lot of value compared to using java library is carmine (a redis client lib). https://github.com/ptaoussanis/carmine
since the redis protocol has a https://github.com/antirez/redis-doc/blob/master/commands.json. you don’t really have to worry about it not supporting some feature
Last commit was 22 days ago: https://github.com/weavejester/clojure-toolbox.com/commits/master
@dharrigan nice! Thanks
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))
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)
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
🙂 ).