Howdy y'all! Is there a formatter for edn files? one that adds indentation and line breaks?
Maybe this? https://github.com/kkinnear/zprint
What is the output of clojure -Sdescribe
?
It might be that you have an older version of the Clojure CLI tools than Sean was using when creating those files -- there have been changes in the last few months, especially around handling of the -X
command line options.
if I have a regex, is there a way to get a match object that has indices of groups instead of the groups themselves?
e.g. if I have .(.)x
or something Iād like the indices of where each part starts and ends
Finally looking at this, this is a great example of why mutability is a nightmare. This is so hard to work with!
It certainly can be. In this case, as long as you copy all of the pieces of a match result out of a mutable JVM object before using it again, you should be good.
The underlying Java APIs used by Clojure/JVM to do regex matching should provide these indexes. IIRC using those indexes is exactly how Clojure determines the substrings of the input string to return for the match groups.
Look at the methods start
and end
for the class java.util.regex.Matcher
: https://docs.oracle.com/javase/9/docs/api/java/util/regex/Matcher.html
Trying to do āWeb Development with Clojure 3rd editionā and after creating the base app with luminus and h2 as suggested, still getting āNo suitable driverā for database connection. H2 dependency is there. What the heck?
Thank you š that should do the trick
Hi team, please suggest a logging tool for Clojure application?
Everything is saved, and your REPL was restarted after adding the dependency?
@vnazaryan clojure.tools.logging
They asked this in #clj-new and it's because they have ...
in deps.edn
which causes the map literal error.
@twcrone I saw that youād posted this same Q on StackOverflow so Iāve followed up there ā I canāt repro the error based on the information youāve provided so far (my answer shows the steps that work).
@vnazaryan Now Iām at my desk I can expand on my answer: using clojure.tools.logging
, it will look for a Java logging library on your classpath. It looks for known libraries in a particular order, starting with slf4j. At work, weāve decided to use log4j2, and we ābridgeā all the other logging libraries over to log4j2 by having these dependencies in our project:
;; use log4j 2.x:
org.apache.logging.log4j/log4j-api {:mvn/version "2.13.3"}
;; bridge into log4j:
org.apache.logging.log4j/log4j-1.2-api {:mvn/version "2.13.3"}
org.apache.logging.log4j/log4j-jcl {:mvn/version "2.13.3"}
org.apache.logging.log4j/log4j-jul {:mvn/version "2.13.3"}
org.apache.logging.log4j/log4j-slf4j-impl {:mvn/version "2.13.3"}
And we also have to tell clojure.tools.logging
to select log4j2 instead of just whatever it finds first (since most non-trivial apps end up with multiple logging libraries in play) so we pass this JVM option:
-Dclojure.tools.logging.factory=clojure.tools.logging.impl/log4j2-factory
(how exactly you pass that in will depend on what tooling youāre using to run/test/build your program)Yeah itās silly, I literally created and ran. Which by all accounts should just work. Figure I missed a step. Iāll look at more tonite. Didnāt spend much time since I figure was a stupid omission that is common
If you update your SO post with any new information, LMK, so I can update my answer.
Also if youāre confused about various Java logging libraries (as most of us are) hereās some background: https://lambdaisland.com/blog/2020-06-12-logging-in-clojure-making-sense-of-the-mess
>> (type (cons "asdf" [1 2 3]))
clojure.lang.Cons // expecting this to be persistentList
Any idea why this not persistentList.If that where so what would happen if you did (cons 1 (range))
and also from the docstring you should not have that expectation: > clojure.core/cons > ([x seq]) > Returns a new seq where x is the first element and seq is > the rest.
I think my understanding of seq
is flawed, cons returns a seq but why does the type say clojure.lang.Cons?
(seq? (cons "asdf" [1 2 3])) ;; true
this guide is by far the most authoritative: https://clojure.org/reference/sequences
but the short and sweet is that, if you're familiar with other lisps, seq provides the "car" and "cdr" to many different types not just the two pointer cons cell