This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-06-20
Channels
- # announcements (5)
- # asami (7)
- # babashka-sci-dev (36)
- # beginners (50)
- # calva (47)
- # cider (1)
- # clj-kondo (19)
- # clojure (33)
- # clojure-europe (25)
- # clojure-nl (2)
- # clojure-uk (4)
- # clojurescript (26)
- # conjure (2)
- # cursive (5)
- # datalog (6)
- # fulcro (5)
- # graalvm (12)
- # leiningen (1)
- # malli (30)
- # off-topic (5)
- # rdf (4)
- # ring (11)
- # shadow-cljs (55)
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.
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 projectsHi folks, can I add custom feature for reader_conditionals? How to do that? And will work like this -Dclojure.features=arch/osx ?
It is not an open system for the purposes of reading and evaluating source so you can't add a feature
It is possible to invoke the reader directly and pass extra features etc but I suspect That's not what you want
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 https://clojuredocs.org/clojure.core/iterate, but that function will not take anything but a number as its second argument.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 đ
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?
https://clojuredocs.org/clojure.core/dotimes do times springs to mind though
@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))
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.
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)
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:
I'm sure there is something like "NumberFormat.parse" for parsing such a string "1,505,000"
(.parse (NumberFormat/getInstance Locale/US)
"1,505,000")
=> 1505000
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
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
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?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
It is a singleton afaik
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
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
so the question is ... do you feel lucky?
(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)