Fork me on GitHub
#beginners
<
2022-06-20
>
oly07:06:24

Everyone favourite more logging issues, got a question regarding versions seems https://www.slf4j.org/codes.html#noProviders seems I can choose versions under 1.8 or over, but version 1.8 upwards seem to be marked as alpha versions curious what versions everyone is using ? any recommendations or deps blocks of working up to date versions, or should I just go with the newer pre release versions trying to use slf4j and logback-classic which seems quite a standard setup.

plexus05:06:50

Unless you need specific new features I would take the latest non-alpha version.

oly12:06:08

I think that's what broke my logging I switched to latest, I have got it working but using an alpha as I noticed reitit has the most up to date version which was an alpha so I matched that version, it may have been that library that was causing my issues

oly12:06:35

I ended up with these versions

org.slf4j/slf4j-api {:mvn/version "2.0.0-alpha6"}
        org.slf4j/log4j-over-slf4j {:mvn/version "2.0.0-alpha6"}
        ch.qos.logback/logback-classic {:mvn/version "1.3.0-alpha16"}
I guess exclusions may have been an option, though I am sure I read they are rarely needed in deps projects

Alex Sky13:06:58

Hi folks, can I add custom feature for reader_conditionals? How to do that? And will work like this -Dclojure.features=arch/osx ?

Alex Miller (Clojure team)13:06:42

It is not an open system for the purposes of reading and evaluating source so you can't add a feature

🙏 1
Alex Miller (Clojure team)13:06:21

It is possible to invoke the reader directly and pass extra features etc but I suspect That's not what you want

emccue13:06:48

You can likely do what you want with a regular macro

Alex Sky14:06:49

thx a milloin for the help! Yes, I want a similar mechanism for my purposes. Okay) I will try to implement mine through data-readers/macro

Eric14:06:58

Suppose I have a function, f , that takes a vector and returns a vector. For simplicity’s sake, we could define it like:

(defn f [coll] (map inc coll))
What is the simplest way to call foo on a vector 100 (or N) times? The result should be f(f(f(…f(x)))). This looked exactly like the description of https://clojuredocs.org/clojure.core/iterate, but that function will not take anything but a number as its second argument.

oly14:06:18

(defn f [coll] (mapv inc (take 100 coll)))
perhaps something like that ? untested

Alex Miller (Clojure team)14:06:20

iterate is lazy, so can call nth on the result of iterate

oly14:06:29

actually scratch that you want to run on all items 100 times not on a 100 items 🙂

👍 1
dpsutton14:06:21

I’m confused about why iterate doesn’t work for you because “that function will not take anything but a number as its second argument”. What would you want to pass as a second argument?

Eric14:06:01

@U064X3EF3 I would have thought so, but iterate won’t take my vector there.

Eric14:06:06

@U11BV7MTK Here’s what I tried:

(take 100 (iterate f v))

Eric14:06:27

Where v is a vector

dpsutton14:06:30

(nth (iterate shuffle [:a :b :c]) 30) returns [:b :a :c]

🙏 1
Eric14:06:01

Oh! :thinking_face:

Eric14:06:31

Ok, let me try that form. I think nth is what I want anyway, not take.

dpsutton14:06:20

it’s Alex’s point from earlier. I was just writing an example showing that iterate doesn’t require a number as the second arg.

👍 1
Alex Miller (Clojure team)14:06:28

user=> (defn f [coll] (map inc coll))
#'user/f
user=> (take 5 (iterate f [0 1 2]))
([0 1 2] (1 2 3) (2 3 4) (3 4 5) (4 5 6))
user=> (nth (iterate f [0 1 2]) 4)
(4 5 6)

🙏 1
Eric14:06:34

Ahh, yes. I just tried it too.

🎉 1
Eric14:06:53

The take was screwing it up. Thanks, guys!

Eric14:06:23

In case you guys occasionally like to see what you’re actually helping people accomplish, here is what I just got working with your help… My (terrible) interpolation function after 10 iterations:

👍 1
Eric14:06:42

And then after 400:

🎉 2
👍 2
Benjamin16:06:35

I'm sure there is something like "NumberFormat.parse" for parsing such a string "1,505,000"

Martin PĹŻda16:06:09

(.parse (NumberFormat/getInstance Locale/US)
        "1,505,000")

=> 1505000

Andrzej16:06:14

Of course, there is

Alastair Hole16:06:32

Is there a recommended method (library?) of reading config from environment variables (over and above System/getenv)?

Benjamin16:06:14

if you don't need to keep clojurescript compatibility in mind then it is idiomatic to just use java interop

👍 1
Benjamin16:06:33

if you want some advanced config https://github.com/juxt/aero there is also at least 1 lib that reads from command line args, then env vars etc. finding the first provided

👍 1
Alastair Hole16:06:01

Great, thanks I will take a look 🙂

Benjamin17:06:02

Jo I'm guessing java.text.NumberFormat/getNumberInstance is not thread safe but I am not sure

(let [o (Object.)]
  (defn parse-number [s]
    (locking o
      (.parse (java.text.NumberFormat/getNumberInstance) s))))
does this here make sense or am I making a mistake?

Alex Miller (Clojure team)17:06:06

You're correct that they are not thread safe l. You can either lock as you are or use a threadlocal

delaguardo17:06:09

In case you create number instance every time you call parse-number you don't need to worry about synchronisation

Benjamin17:06:38

ah getInstance sounded like it is returning some singleton. If that returns a fresh instance then yea I have a fresh instance everytime

Alex Miller (Clojure team)17:06:57

It is a singleton afaik

Alex Miller (Clojure team)17:06:08

A non-threadsafe singleton

😅 1
kappa 1
delaguardo18:06:20

hm... I wonder if checking identical? is enough to confirm that it is not singleton?

(identical?
 (java.text.NumberFormat/getNumberInstance)
 (java.text.NumberFormat/getNumberInstance)) 
;; => false

Alex Miller (Clojure team)18:06:55

I see nothing that says that it can't be a singleton (and when I looked at the jdk code, that's what it looked like to me), and the javadoc for the class says that it's not thread safe

Alex Miller (Clojure team)18:06:04

so the question is ... do you feel lucky?

Alex Miller (Clojure team)18:06:25

(as someone that has debugged this exact problem in a production scenario, I do not)

delaguardo18:06:19

I do not either) I prefer to treat javadocs as a holy scrolls. my question comes out just because of curiosity

seancorfield18:06:08

If you're on Clojure 1.11, and you know s is a string, you could do (or (parse-long s) (parse-double s)) -- or just one of those if you are expecting either a long or a double but not possibly both.

seancorfield18:06:04

Or are you getting some string that may have comma separators in it? (for thousands)