This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-05-23
Channels
- # ai (1)
- # aleph (1)
- # announcements (7)
- # babashka (87)
- # beginners (34)
- # biff (9)
- # clerk (4)
- # clojars (37)
- # clojure (144)
- # clojure-art (12)
- # clojure-europe (13)
- # clojure-nl (1)
- # clojure-norway (4)
- # clojure-uk (2)
- # clr (5)
- # conjure (1)
- # data-science (1)
- # datahike (7)
- # datalevin (6)
- # datomic (13)
- # events (1)
- # fulcro (1)
- # graalvm (5)
- # gratitude (1)
- # honeysql (4)
- # hyperfiddle (122)
- # malli (26)
- # nbb (2)
- # off-topic (16)
- # portal (93)
- # practicalli (1)
- # re-frame (1)
- # reitit (15)
- # releases (3)
- # remote-jobs (1)
- # shadow-cljs (5)
- # tools-deps (6)
- # xtdb (4)
Hi, Quick question as I build my skills using clojure i'd like to keep a close eye to potential clojure style guides, i've browsed two found from slack so far but neither of them seem to support automated linting that complains to me whenever I write the code in vscode for example. Are there such linters for commonly used/approved styleguides in clojure?
Do you use clojure-lsp
?
It has clj-kondo
built-in, which is the main linter.
Currently i'm not using any but it seems that clj-kondo is available for vs-code. Thank you very much for pointing me in the right direction
For VS Code, you will want to install Calva. It comes with clojure-lsp and clj-kondo.
Hmm I was just looking at that, Calva is installed yet I see precious few warnings in my code. I don't think i'm that good as a beginner, so might need to play around to see if it's working right
clj-kondo has a lot of optional linters. Borkdude likes making new linters, but is pretty frugal about pushing them on people by default. If you see some warnings, but want to see more, Checkout the docs to add more linters to your setup. https://github.com/clj-kondo/clj-kondo/blob/master/doc/config.md#options https://github.com/clj-kondo/clj-kondo/blob/master/doc/linters.md
Thank you kindly I'll be sure to take a look
In terms of style guides, this one is the most widely followed: https://guide.clojure.style/ -- I'm not sure how much of it clj-kondo can enforce but Calva + LSP + Kondo is a great combination with VS Code!
I am getting weirdly stumped by this: how do I turn a list of characters into a string? I've so far managed to just map
with str
over the list - how can I join them?
Okay thank you @U11BV7MTK
The fact that they are characters is irrelevant. It’s just dealing with the collection
is there an arity limit on apply str? would a phenomenally long list of characters via apply break a call to str
?
https://clojuredocs.org/clojure.string/join can be used for this as well
@U01188CHUFL when you give many arguments to str, it is just a loop over the sequence adding one by one to a StringBuilder, so should be ok https://github.com/clojure/clojure/blob/master/src/clj/clojure/core.clj#L556-L561
clojure.string/join does the same, so they should be equivalent on the perf side
I did not validate it. But I would give reduce a try.
(reduce #(str %1 %2) "" ["o" "l" "a"])
Strings are horrible accumulators for more strings. Look at the source of str to see how it accumulates parts of the final string in its reduce
it is going to constantly be creating StringBuilders and discarding them after adding one more String
also looks uglier than (apply str [...]) imo
the only thing faster is if your original list of chars is a char[], then you can just build the string with the char[] constructor, like (String. (char-array [\a \b \c]))
regardless of aesthetics, it can be catastrophic on large collections
(let [coll (repeat 1000000 "a")]
(time (count (apply str coll)))
(time (count (reduce str "" coll))))
"Elapsed time: 54.076833 msecs"
"Elapsed time: 49594.28475 msecs"
1000000
.054 seconds vs 49 secondsNice! Thanks for the insight! Another doubt i was thinking of now: from a bigO notation perspective it would run the same amount, correct?
yeah, I guess it depends if the constructor is O(1)
looking at the source, it isn't, it copies the CharSequence, so I was wrong, it isn't O(n)