Fork me on GitHub
#beginners
<
2021-03-21
>
vlad_poh10:03:52

Howdy y'all! Is there a formatter for edn files? one that adds indentation and line breaks?

dharrigan10:03:23

Maybe this? https://github.com/kkinnear/zprint

šŸ‘ 3
ā˜ļø 3
andy.fingerhut14:03:05

What is the output of clojure -Sdescribe ?

andy.fingerhut14:03:43

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.

seancorfield17:03:06

They asked this in #clj-new and it's because they have ... in deps.edn which causes the map literal error.

grazfather15:03:55

if I have a regex, is there a way to get a match object that has indices of groups instead of the groups themselves?

grazfather15:03:06

e.g. if I have .(.)x or something Iā€™d like the indices of where each part starts and ends

andy.fingerhut15:03:09

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.

andy.fingerhut15:03:56

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

grazfather15:03:29

Thank you šŸ™‚ that should do the trick

grazfather14:03:22

Finally looking at this, this is a great example of why mutability is a nightmare. This is so hard to work with!

andy.fingerhut14:03:12

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.

Todd15:03:16

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?

javahippie16:03:35

Everything is saved, and your REPL was restarted after adding the dependency?

seancorfield18:03:00

@U01NN34TJUB 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).

Todd18:03:07

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

3
seancorfield18:03:40

If you update your SO post with any new information, LMK, so I can update my answer.

Karo15:03:04

Hi team, please suggest a logging tool for Clojure application?

seancorfield17:03:08

@vnazaryan clojure.tools.logging

thanks2 3
seancorfield18:03:51

@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)

valtteri19:03:45

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

piyer19:03:56

>> (type (cons "asdf" [1 2 3]))
clojure.lang.Cons // expecting this to be persistentList
Any idea why this not persistentList.

dpsutton19:03:24

If that where so what would happen if you did (cons 1 (range))

dpsutton19:03:45

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.

piyer20:03:11

I think my understanding of seq is flawed, cons returns a seq but why does the type say clojure.lang.Cons?

piyer20:03:53

(seq? (cons "asdf" [1 2 3])) ;; true

dpsutton20:03:20

this guide is by far the most authoritative: https://clojure.org/reference/sequences

dpsutton20:03:55

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

šŸ‘ 3