Fork me on GitHub

Everyone favourite more logging issues, got a question regarding versions seems 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.


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


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


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


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


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, but that function will not take anything but a number as its second argument.


(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


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

👍 1

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?


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


@U11BV7MTK Here’s what I tried:

(take 100 (iterate f v))


Where v is a vector


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

🙏 1

Oh! :thinking_face:


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


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=> (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

Ahh, yes. I just tried it too.

🎉 1

The take was screwing it up. Thanks, guys!


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

And then after 400:

🎉 2
👍 2

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)

=> 1505000


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


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

👍 1

if you want some advanced config 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 🙂


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


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


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

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

;; => 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)


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


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.


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