clojure

New to Clojure? Try the #beginners channel. Official docs: https://clojure.org/ Searchable message archives: https://clojurians-log.clojureverse.org/
JAtkins 2020-10-13T03:16:51.379200Z

Anyone remember where this is? I saw about a month ago a talk on clojure code management where the guy never put code into files, instead placing it in a database. I'm afraid I can't be more specific since it's been too long 😜

😂 1
JAtkins 2020-10-13T17:00:25.421300Z

More like unison: https://www.unisonweb.org

anonimitoraf 2020-10-13T05:43:26.379400Z

Datomic as source control? :thinking-face:

rmxm 2020-10-13T09:15:01.382700Z

I am wondering on usage of memoization/ttl. My question regarding is: if the cache is invalidated and memoized function get called several times in mutlithreaded env how will it behave? Will there be one computation for the first cache miss and waiting on result from subsequent invocations or will all pending invocations go compute the value? I am thinking if background tasks that are basically "fetch data from other service and update value every X minutes" can be effectively replaced with memo/ttl.

2020-10-13T11:17:52.384100Z

Has anyone experienced segfaults with REBL / AdoptOpenJDK 11 on MacOS, and… have pointers on what to do to fix it

2020-10-13T11:18:12.384200Z

It works perfectly fine on 8, but as soon as I switch to 11, I get segfaults

2020-10-13T11:18:45.384400Z

Tried AdoptOpenJDK 15, also segfaults

2020-10-13T11:22:37.384600Z

… bit vague, I know, I was kinda hoping that it rings a bell with someone :)

2020-10-13T11:35:03.384800Z

It appears to segfault in libjfxwebkit?

jumar 2020-10-13T12:09:51.386200Z

You may want to examine the error file and loook for s corresponding jdk bug

2020-10-13T12:11:10.386600Z

Yeah looking at logs, it is trying to find libraries in the maven repository > WARNING: java.lang.UnsatisfiedLinkError: Can’t load library: ~/.m2/repository/org/openjfx/javafx-graphics/11.0.2/libjfxwebkit.dylib > > Loaded library /libjfxwebkit.dylib from resource

rmxm 2020-10-13T12:37:42.387400Z

Ok, so I did some practiacl testing and it seems data will not be computed several times when there is a computation pending.

alexmiller 2020-10-13T13:23:29.389100Z

In Oracle Java 8, JavaFX is built in. In later Java’s, you need openjavafx as an additional set of libraries

2020-10-13T13:23:35.389400Z

any niche application of (bounded-count) ?

alexmiller 2020-10-13T13:25:14.389900Z

You can see the set of required deps at https://docs.datomic.com/cloud/other-tools/REBL.html

alexmiller 2020-10-13T13:25:47.390300Z

Are you using those deps?

2020-10-13T13:26:44.390800Z

I’m using them in my lein profile:

{:tools {:plugins [[lein-ancient "0.6.15"]
                   [lein-localrepo "0.5.4"]]}
 :rebl {:repl-options  {:nrepl-middleware [nrebl.middleware/wrap-nrebl]}
        :dependencies  [[rickmoynihan/nrebl.middleware "0.2.0"]
                        [com.cognitect/rebl "0.9.242"]
                        [org.openjfx/javafx-fxml "11.0.2"]
                        [org.openjfx/javafx-controls "11.0.2"]
                        [org.openjfx/javafx-swing "11.0.2"]
                        [org.openjfx/javafx-base "11.0.2"]
                        [org.openjfx/javafx-web "11.0.2"]
                        [cljfmt "0.6.4"]]
       :resource-paths ["*snip*/REBL-0.9.220/REBL-0.9.220.jar"]
       :injections     [(require 'nrebl.middleware) (require '[cognitect.rebl :as rebl])]
       :jvm-opts       ["-Djavafx.verbose=true"]}
 :user [:tools :rebl]}

alexmiller 2020-10-13T13:27:28.391300Z

But those are different versions

2020-10-13T13:28:30.392200Z

Yeah, let me try with that 15 version, followed a bit of a mixed set of advice

alexmiller 2020-10-13T13:28:33.392400Z

Even if you are on Java 11, you should use the newer javafx libs

2020-10-13T13:28:39.392600Z

my two cents, it's mainly for places where you want to know if (count x) is greater than some value y

alexmiller 2020-10-13T13:28:52.393100Z

And you shouldn’t need the cljfmt dep

alexmiller 2020-10-13T13:29:56.394Z

You also seem to have one version of rebl in the deps and another in the resources?

2020-10-13T13:31:50.394200Z

Yeah, I set it straight like this:

{:tools {:plugins [[lein-ancient "0.6.15"]
                   [lein-localrepo "0.5.4"]]}
 :rebl {:repl-options  {:nrepl-middleware [nrebl.middleware/wrap-nrebl]}
        :dependencies  [[rickmoynihan/nrebl.middleware "0.2.0"]
                        [com.cognitect/rebl "0.9.242"]
                        [org.openjfx/javafx-fxml "15-ea+6"]
                        [org.openjfx/javafx-controls "15-ea+6"]
                        [org.openjfx/javafx-swing "15-ea+6"]
                        [org.openjfx/javafx-base "15-ea+6"]
                        [org.openjfx/javafx-web "15-ea+6"]]
       :injections     [(require 'nrebl.middleware) (require '[cognitect.rebl :as rebl])]
       :jvm-opts       ["-Djavafx.verbose=true"]}
 :user [:tools :rebl]}
Those are the versions I found here: https://docs.datomic.com/cloud/other-tools/REBL.html#installation but in leiningens format I found some instructions by Sean, which was the mixed advice: https://github.com/RickMoynihan/nrebl.middleware/issues/23#issuecomment-533243271

2020-10-13T13:33:55.394600Z

Same problem tho, still get a segfault.

# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00000001047de1a4, pid=11576, tid=121871
#
# JRE version: OpenJDK Runtime Environment AdoptOpenJDK (11.0.8+10) (build 11.0.8+10)
# Java VM: OpenJDK 64-Bit Server VM AdoptOpenJDK (11.0.8+10, mixed mode, tiered, compressed oops, g1 gc, bsd-amd64)
# Problematic frame:
# V  [libjvm.dylib+0x3de1a4]  jni_CallStaticBooleanMethodV+0xdf

2020-10-13T13:34:50.395200Z

(Thanks btw!)

alexmiller 2020-10-13T13:36:19.396Z

Those set faults were fixed in the openjfx 15 early access versions

alexmiller 2020-10-13T13:37:00.396600Z

Or one set were, maybe this is something new

alexmiller 2020-10-13T13:37:18.397Z

I haven’t seen that before

2020-10-13T13:41:20.397200Z

It’s also crashing with the released openjfx 15 versions. (e.g. ["org.openjfx/javafx-… "15"]). So that openjfx option I enabled, gives me this warning:

WARNING: java.lang.UnsatisfiedLinkError: Can't load library: *snip*/.m2/repository/org/openjfx/javafx-graphics/15/libprism_es2.dylib
Loaded library /libprism_es2.dylib from resource
(and of a bunch of other dylib’s) Is that expected?

mpenet 2020-10-13T13:59:18.397700Z

... and on something not ICounted 🙂

mpenet 2020-10-13T14:00:10.398100Z

oh, it actually does that check

Søren Sjørup 2020-10-13T14:13:41.399800Z

With clj -X:deps mvn-pom is there a way to specify what version should be put in the pom file?

alexmiller 2020-10-13T14:19:12.400300Z

not at the moment - you set it in the source pom

alexmiller 2020-10-13T14:19:40.400600Z

but you should really use clj -Spom for now

Søren Sjørup 2020-10-13T14:20:50.401300Z

Thank you for the quick response. Can I specify version on the command line with clj -Spom ?

alexmiller 2020-10-13T14:21:11.401500Z

no, no difference in that regard

alexmiller 2020-10-13T14:22:05.402400Z

the internals have been reworked to support that kind of configurability and that's coming but working on other things atm

Søren Sjørup 2020-10-13T14:22:14.402500Z

Ok thanks a lot.

borkdude 2020-10-13T14:32:05.403100Z

@soren.sjorup Since this question comes up a lot, I decided to write a script for it: https://github.com/borkdude/babashka/blob/master/examples/set_pom_version.clj

💎 1
Søren Sjørup 2020-10-13T14:34:46.403600Z

Thank you so much. Big babashka fan!

Søren Sjørup 2020-10-13T14:44:58.403800Z

My tags are qualified so I needed to change the condition to (and (:tag elt) (= "version" (name (:tag elt))))

borkdude 2020-10-13T14:46:50.404800Z

ah I see, where is that difference coming from?

Søren Sjørup 2020-10-13T14:48:20.406Z

I have xmlns=“<http://maven.apache.org/POM/4.0.0>” in the project tag.

borkdude 2020-10-13T14:48:54.406200Z

Ah, that makes sense. Feel free to PR the update if you so wish

Søren Sjørup 2020-10-13T14:49:56.406400Z

Sure will do. Thanks a lot! Spent way to much time on this today.

seancorfield 2020-10-13T14:56:36.406600Z

@lennart.buit Which macOS are you on? Since I switched to the 15-ea+6 OpenJFX, I've had no problems on macOS 10.12, running AdoptOpenJDKs 11, 14, or 15.

borkdude 2020-10-13T14:57:12.406800Z

Updated it already

seancorfield 2020-10-13T14:57:16.407Z

I have seen that warning on Ubuntu (on WSL2 on Windows 10) but it still loads and runs just fine (via Xlaunch).

2020-10-13T14:57:17.407200Z

I’m on Mojave 10.14

Søren Sjørup 2020-10-13T14:58:40.407400Z

(def xml (xml/parse-str (slurp pom-xml) :namespace-aware false)) also works.

seancorfield 2020-10-13T14:59:13.407600Z

Is there anything specific that you do that results in the segfault, or is it random?

borkdude 2020-10-13T14:59:15.407800Z

ah good one

2020-10-13T14:59:36.408Z

Starting rebl, guaranteed segfault: (rebl/ui)

seancorfield 2020-10-13T14:59:42.408200Z

(I'll note that I don't use lein or nREPL at all so that may be a factor in what you're seeing)

2020-10-13T15:00:08.408400Z

instead of that construction with and you could use the extra arg to the keyword

(= "version" (name (:tag elt "")))

alexmiller 2020-10-13T15:00:42.408700Z

is there some reason you are using "15" and not "15-ea+6" as in the docs?

2020-10-13T15:01:29.409Z

(I guess that was at Sean? I tried both with the same results)

alexmiller 2020-10-13T15:01:35.409200Z

I haven't actually tested rebl with the final 15 release

borkdude 2020-10-13T15:02:02.409400Z

I made it into:

(if-let [t (:tag elt)]
    (if (= "version" (name t))
      (assoc elt :content version)
      elt)
    elt)

2020-10-13T15:02:42.409600Z

Oh, I interpreted “Those set faults were fixed in the openjfx 15 early access versions” as “try final” 🙂. My bad, but I’m still having the crashes with -ea+6

Søren Sjørup 2020-10-13T15:04:13.409800Z

with :namespace-aware false we don’t need name in there.

2020-10-13T15:06:05.411500Z

When running from CLI, is there anything to do to output the result? I have a very simple file and I can't get it to show anything.

(ns myns)

(defn -main
  [&amp; args]
  (+ 1 2))
Running with clojure -m myns.

borkdude 2020-10-13T15:06:08.411600Z

I leave the tweaking to the end user. However, I'm interested in a fix for getting the XML declaration and the first tag to be pretty printed better.

borkdude 2020-10-13T15:06:21.411800Z

I'm actually getting:

&lt;?xml version="1.0" encoding="UTF-8"?&gt;&lt;project&gt;
    &lt;version&gt;1.0.2&lt;/version&gt;
&lt;/project&gt;

2020-10-13T15:06:44.412Z

hey interesting, it works with a deps.edn

alexmiller 2020-10-13T15:07:16.412500Z

I've used a bunch of different java vendors, and jdk versions, and open javafx versions and have never seen the issue you're reporting

alexmiller 2020-10-13T15:07:33.413Z

but I always use deps.edn, not lein so there may be some difference there, not sure what

Søren Sjørup 2020-10-13T15:07:46.413600Z

Yes I also get the &lt;?xml and &lt;project on the same line. But it’s not high prio for me.

dpsutton 2020-10-13T15:07:48.413800Z

if you want to print to stdout you can use println.

2020-10-13T15:08:09.414Z

Oh derp, of course.

2020-10-13T15:08:13.414200Z

Thank you very much

borkdude 2020-10-13T15:08:17.414300Z

:thumbsup:

borkdude 2020-10-13T15:08:32.414900Z

you can also do a str/replace on that

2020-10-13T15:08:47.415500Z

I'm halfway surprised -main doesn't return exit code 3

2020-10-13T15:09:03.416100Z

but only halfway :D

alexmiller 2020-10-13T15:09:03.416200Z

that would be deeply weird :)

2020-10-13T15:09:15.416800Z

Is babashka related to gravvl vm or something? How does that bb executable come from?

Søren Sjørup 2020-10-13T15:09:23.416900Z

On what sorry?

2020-10-13T15:09:30.417100Z

clearly I've been doing too much low-level programming lately

borkdude 2020-10-13T15:09:59.417300Z

@i It is related. Babashka is a tool that runs Clojure code through an interpreter that is compiled with GraalVM.

2020-10-13T15:10:28.417600Z

fast for interactive use?

2020-10-13T15:10:57.417800Z

Really appreciate all the help so far 🙂

borkdude 2020-10-13T15:11:03.418100Z

It has worse performance than JVM Clojure, but better startup (few milliseconds).

borkdude 2020-10-13T15:11:43.418500Z

To get the XML declaration straightened

2020-10-13T15:11:49.418700Z

I’m at least glad it works with a deps.edn, now its something lein related

2020-10-13T15:12:00.418900Z

At least easier finding ^^

Søren Sjørup 2020-10-13T15:13:15.419100Z

Yeah sure. But I’m not going to read it. 🙂

borkdude 2020-10-13T15:13:40.419300Z

That's the spirit :)

2020-10-13T15:18:10.419500Z

just tried. quite fast. the only thing annoying is, when downloading the binary from github, chrome prompts that this file is seldom downloaded and might not be safe. Also, when execute the binary for the first time, macos says its not signed might not be safe ….

borkdude 2020-10-13T15:19:19.419700Z

You can also install it through brew

Søren Sjørup 2020-10-13T15:20:46.419900Z

🙂 Again thank you so much for making babashka. I never got around to learning bash. But I love Clojure!

borkdude 2020-10-13T15:21:10.420100Z

Same here!

Søren Sjørup 2020-10-13T15:25:00.420300Z

🙂

borkdude 2020-10-13T16:26:05.420600Z

actually clj-kondo does return exit code 0, 2 or 3 with meaning attached to it

borkdude 2020-10-13T16:26:13.420800Z

1 is reserved for unexpected errors

2020-10-13T16:33:20.421100Z

yeah, but that's quite different from using the last expression in -main as an OS level return value (and more useful of course)

unbalanced 2020-10-13T21:43:24.423200Z

I'm very curious about the humble preserving-reduced function in the core library. Does anyone have any insight into this?

unbalanced 2020-10-13T21:44:04.424400Z

I see that it's used in cat and if something is reduced it wraps it with another reduced ... that seems very strange but I'm sure there's a very good reason for it

unbalanced 2020-10-13T21:47:04.425600Z

Also I understand that it's just an implementation detail of transducers but I can't for the life of me figure out what cases this covers.

ghadi 2020-10-13T21:47:27.426100Z

if you have nested calls to reduce, as in cat, and the inner call to reduce short circuits with reduced, you don't want to resume reducing with the outer call to reduce

ghadi 2020-10-13T21:48:35.427500Z

so you double wrap so that when the inner reduce short circuits, it unwraps one layer, then the outer reduce unwraps the other layer

ghadi 2020-10-13T21:49:16.428200Z

cat is a transducer that is used in some reducing context which is the outer layer

ghadi 2020-10-13T21:49:29.428600Z

the inner layer is the call to reduce that is on the last line of cat

unbalanced 2020-10-13T21:51:42.429900Z

ohhhhhhhhhhkay that makes perfect sense

1
2020-10-13T22:02:03.431300Z

For the internet travellers: For me, it doesn’t segfault when lein can find a project.clj, in folders that are not lein projects it does still, tho. Thats a situation that works for me, I think.

hanDerPeder 2020-10-13T22:07:24.433500Z

anybody gotten an uberjar to run under procrun on windows? keep getting an error saying it can’t find the class file. I’m able to call my gen-class static method using a java program with the uberjar on the classpath.

2020-10-13T22:15:06.433800Z

Have you checked the uberjar to see if the class is in there?

2020-10-13T22:15:35.434Z

the first thing I would test is java -jar the.jar - you need more than just the class existing, you need to either ask for the right class or have the right default entrypoint

hanDerPeder 2020-10-13T22:25:03.434200Z

replaced my uberjar with a minimal one, which works. so now I just have to figure out whats different. thanks for the input!