This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-08-03
Channels
- # announcements (5)
- # babashka (7)
- # beginners (119)
- # biff (4)
- # cider (7)
- # clj-kondo (26)
- # cljfx (3)
- # cljs-dev (2)
- # clojure (28)
- # clojure-austin (18)
- # clojure-europe (9)
- # clojure-france (6)
- # clojure-norway (4)
- # clojure-uk (3)
- # clojurescript (6)
- # community-development (1)
- # core-async (4)
- # cursive (9)
- # data-science (12)
- # datomic (13)
- # duct (18)
- # emacs (15)
- # etaoin (5)
- # events (13)
- # honeysql (46)
- # hyperfiddle (9)
- # jackdaw (5)
- # jobs (13)
- # keechma (4)
- # lsp (37)
- # malli (32)
- # nbb (14)
- # off-topic (10)
- # other-languages (2)
- # polylith (4)
- # programming-beginners (3)
- # reagent (27)
- # reitit (1)
- # shadow-cljs (32)
- # sql (11)
- # tools-build (5)
- # tools-deps (3)
- # vim (14)
- # xtdb (11)
java interop Q: I'm trying to generate a stream of dates like so (apparently wrong):
=> (def a-list-of-dates (. LocalDate (datesUntil (. LocalDate now))))
and I get:
Syntax error (IllegalArgumentException) compiling . at (REPL:1:22).
No matching method datesUntil found taking 1 args for class java.time.LocalDate
but browsing the Java docs the only reason given for an IllegalArgumentException
is "if end date is before this date". Which clashes not only with my java-ignorant intuition (is LocalDate
using the Unix epoch or something like it?) but also with what the Java docs show, namely that there is such a datesUntil
method on the LocalDate
class that takes one argumenthttps://docs.oracle.com/javase/9/docs/api/java/time/LocalDate.html#datesUntil-java.time.LocalDate- this is an instance method. So you need (.datesUntil <instance> <end-exclusive>)
(.datesUntil (LocalDate/now) (LocalDate/parse "2022-12-25"))
->
LocalDate.now().datesUntil(then)
(iterator-seq (.iterator (.datesUntil (LocalDate/now) (LocalDate/parse "2022-12-25"))))
Given a vector of single-entry maps, what's the best way to get a list of the values?
val
works on map-entries, vals
works on maps.
(map val ...
is not very common, and it'll break when you aren't using map-entries
(map val [{:x 1} {:x 2}])
=> ExceptionInfo
Error printing return value (ClassCastException) at null (REPL:1).
Thanks @U0LAJQLQ1.
if the maps all have a single key (not necessarily specified as such in the original question) you could (map :that-key coll)

really weird error running clj -X:deps mvn-install
:
Execution error (FileNotFoundException) at clojure.tools.cli.api/read-pom-in-jar (api.clj:357).
Jar file not found:
and that's it, a blank line apparently indicating no JAR file at allmoving to thread...
mvn-install is for installing a jar you have into the Maven repository, which you usually don't need to do (usually by referring to it as a dep it is automatically downloaded)
can you clarify the full command you ran and what you're trying to do?
I have a deps.edn
with these contents:
{:deps
{org.clojure/core.async {:mvn/version "1.5.648"}}
{org.clojure/data.json {:mvn/version "2.4.0"}}}
and I was under the impression that in order for those to be available when I run clj
that I have to install them using mvn-install
which I did but I get the above error
I could've sworn that previously I used clj -X:deps mvn-install
to add core.async
to my classpath and make it available in the REPL but I wouldn't stake my life on it
You should be able to just run clj
and it will download those deps before starting the repl
correct, you don't need to call mvn-install here
I don't see any downloads happening when I start the REPL and I get ClassNotFoundException
when I try to require the deps
you may already have those downloads in your .m2 so they don't need to be downloaded
they would be at ~/.m2/repository/org/clojure/core.async/1.5.648/core.async-1.5.648.jar for example
you can check your classpath with clj -Spath
what's the actual repl invocation and response you're seeing?
just plain
clj
Clojure 1.11.1
user=>
and it does appear that data.json
is on my classpath as you said
where's the error?
and the thing that causes the error
user=> (require [org.clojure/data.json :as json])
Syntax error (ClassNotFoundException) compiling at (REPL:1:1).
org.clojure
just in general, a good recipe for asking for help to make it easy for others to help is: I want to do X. I did Y. I got Z, which is wrong/confusing/etc
the namespaces in an artifact are different than the name of artifact itself (which is confusing!)
and they don't even necessarily have any relationship
how would you know that, you might ask... and the answer is, only by reading the documentation
duly noted, on all counts. I will do that more studiously in the future. Thanks a lot for your help
for example, the git readme has an example - https://github.com/clojure/data.json
also note that I quoted the vector passed to require
- this is data passed to a function so to avoid evaluating the symbols inside, it needs to be quoted (which means "read, but don't evaluate")
is there a reason why there is a divergence between artifact naming conventions? Like something to do with the reader syntax? or is it just that there is no hard rule and so things just went that way
jars / artifacts are just containers to hold code
in the early days of Java, there was never any established linkage between how to name / reference libraries and the code inside
there was no package/dependency manager, and it was the wild west
eventually Maven established some conventions, but no one ever created any hard relationship or self describability for jars (beyond just looking at what's in them)
Clojure is really a source-based language with a convention for lookup, but again, basically relied on Java's ecosystem for publishing and consuming artifacts containing code
so, missed opportunities at multiple points in the timeline
interesting history :thinking_face: maybe not the choices I would make but I know very little indeed
I think figuring out library deployment and consumption should probably be on the list of things a language does very early in it's life, otherwise you end up stuck with ad hoc decisions
I think there is more Clojure can do here though and it's something we've been kicking around for many years
the only other language I use with any degree of regularity is Rust since I'm basically a hobbyist and I am very much accustomed to cargo
allowing me to not really think about anything re: dependency management, it's very straightforward
I find it surprising that both of these work:
((fn [{:keys [:x]}] x) {:x 1})
((fn [{:keys [x]}] x) {:x 2}))
Is either one preferred?Interesting that there's a linter in kondo for it. I first spotted the with-colon variety in the kondo code. I suppose if there's a linter for it and it's somewhat of an artifact, the without-colon variety should be preferred. But I think using the colon would offer some benefit when searching the code base for all instances of a keyword.
the latter is preferred
the keyword form was added to support use of autoreferred keywords (`::k`, ::n/k
) but those are now better supported via ::keys
or ::n/keys
Hello! Im looking for any internet resources that elucidate the power and productivity of REPL driven development. This is for my own benefit, but also to refer colleagues who havent seen it before and havent yet got a vision for what it is. Its been a couple of years since I last looked for this sort of content, at which time I think the best I had found was Eric Normand's paid content, and even better was Stuart Halloway's June 2017 talk to Chicago Clojure meetup. Does anyone have any other good references beyond these? Thx in advance!
This is a good one from the illustrious @U04V70XH6: https://www.youtube.com/watch?v=gIoadGfm5T8
How come this pair of functions is called some-fn
and every-pred
, instead of one of them being some-pred
or every-fn
for symmetry?
some-fn
returns the first result of applying each function in turn -- so it will return "logical true"; every-pred
returns true
if everything returns "logical true".
But, yeah, some of this is historical quirks. Like we have every?
and some
-- but any?
means something very different.
What causes Clojure/Java to try to load *.tmp
files from $TMPDIR
on MacOS, and how can I force it to not do that? It's happened occasionally with a few different projects--I'll open a REPL and it will either crash on start or on calling some function with an error that always looks like this:
Execution error (UnsatisfiedLinkError) at java.lang.ClassLoader/loadLibrary (ClassLoader.java:2398).
Can't load library: /var/folders/55/cthyrgtx75z0c3185j99qsx80000gn/T/jna13236126920257902248.tmp
Frustratingly, I can't ever deliberately induce it or repro on other machines--it only seems to occasionally happen when I interrupt CIDER from starting a jack-in
, but then it will affect even command-line REPLs started with clj
or lein repl
. I suspect this is a Java-ism, since most of the SO threads and other help I've seen reference something called a JNI, but I am lost about how to clear or reset this, since reinstalling clojure/tools/clojure
, leiningen
, and even openjdk
via Homebrew and purging the .m2
directory hasn't worked. Any guidance is appreciated 
@U0NCTKEV8 (moving to thread)--is there a good way to narrow down which library is at fault, and/or figure out how to reset it? I suppose if all else fails, I can try analyzing the dependencies one by one, too.
Sounds good, thanks for the help! I will dig a little deeper and see if I can find the problem.
@U03DKTAF52P I'm definitely curious to hear what you find and which libraries seem to be doing this. @U0NCTKEV8 Any idea how to clean things up once they get into a bad state like that, or is it just a case of restarting the REPL and letting it finish loading?
I am not sure, it will depend on what is actually doing the loading and what it is trying to load
This has happened a couple times across a couple projects for me, now--once on a Shadow-CLJS React Native/Expo project, and again as I'm currently working through LambdaIsland's Buddy tutorial (so it's possible that it's a my-machine-problem). Both have had a large stack of their own dependencies. Unfortunately, the issue continues across multiple restarted REPL sessions, so I'm wondering if it's something that's being saved into some hidden configuration. </Speculation>
I have this really wild guess that in this case it might be due the library having native code for osx x86, and trying to load that into the process of a apple silicon native jvm, but that is way out over my skis (not a lot of evidence, and some of the evidence may contradict that)
@U03DKTAF52P Is yours an M1 Mac or an x86 Mac?
M1 on my end. However, I would note that the same REPL load and functional call worked before I interrupted the CIDER REPL load, so it would be weird to me if it was an architecture issue, but that is also far out of my wheelhouse.
if can get the error to happen when using a repl start with clj, that is likely the easiest path to getting a good stacktrace
(FWIW, I always start my REPL manually and just connect my editor to it -- because my REPLs tend to be longer-lived than my editor sessions)
It's better to share actual text -- you can format
code with triple backticks
in Slack.
But that just says that Figwheel failed to started due to the jna class loader error.hawk is, if I recall, a file watching library, and I bet that uses native code for monitoring the fileystem for changes
Based on that stacktrace, it looks like Hawk is the probelm
Yeah, I bet it either doesn't have an M1 version or you need a more up to date version that the project currently has (via Figwheel Sidecar)
Ah. I'll see if bumping the Figwheel dependency up a few versions helps, but that pretty much answers my short-term question. Thanks so much for your help!!
well the barbarysoftware thing that hawk uses on osx seems unlikely to get an update https://github.com/gjoseph/BarbaryWatchService
For future reference--from a fresh install on another M1 Mac, everything seems to work out-of-the-box; both Hawk and Figwheel are behaving correctly. Not sure what I could've done to my existing setup to have borked it (or exactly what I can do to fix it).
Did updating the version(s) of Figwheel and Sidecar help at all?
18.0.2 on the broken one, and 18.0.1 on the working one. I'll upgrade the working one and see if it breaks.
Confirmed that it works OOTB on 18.0.2 as well. Something must be really messed up on my other machine.
besides the version number, are they the same? like maybe the working one is using an x86 jvm above the emulation layer and the broken one is using a native apple silicon jvm
java -version
outputs the following for both:
openjdk version "18.0.2" 2022-07-19
OpenJDK Runtime Environment Homebrew (build 18.0.2+0)
OpenJDK 64-Bit Server VM Homebrew (build 18.0.2+0, mixed mode, sharing)
not super useful I guess, but if you are getting it from homebrew it seems like they should be the same
Hmm. I'll keep digging--at the end of the day, maybe I just need to factory reset my whole machine. Really not sure how this happened.
๐งต(reminder)
what is happening is that library uses some native code, so it has something like a static method that writes the native code out to disk in the tmp file (see jna in the tmp file name) and then tries to link the native code in to the jvm process
Is their a function that takes a function and the number of times to call it? On each step it passes the output of the previous run, e.g.
(do-i-exist f 4 foo)
Would do (f (f (f (f foo)))
?
Right now I'm doing this:
(defn rotate-90ยฐ-n-times [n board]
((apply comp (take n (repeat rotate-90ยฐ-clockwise))) board))
But I'm thinking I'm probably missing somethingiterate
and nth
sounds like what you're looking for?
user=> (take 4 (iterate inc 0))
(0 1 2 3)
user=> (nth (iterate inc 0) 2)
2
user=> (nth (iterate inc 42) 4)
46
user=>
BTW, you can do (repeat n rotate...)
to get n
of that function.
user=> (doc repeat)
-------------------------
clojure.core/repeat
([x] [n x])
Returns a lazy (infinite!, or length n if supplied) sequence of xs.
nil
user=>
How many people here are new to Clojure and would find it useful to have an Intro to Clojure session as a preparation for the https://scicloj.github.io/docs/community/groups/ds4clj/ course?
It'd be helpful to comment in this thread. ๐
me! is there some kind of registration for ds4clj?
Wonderful ๐ There is no registration yet.