Fork me on GitHub
#clojure
<
2019-10-27
>
worlds-endless04:10:47

I'm stumped on some java interop. The line with the comment is stumping me. Any help?

hiredman04:10:23

Why is it stumping you?

hiredman04:10:17

Like, you want to do what is in the comment?

hiredman04:10:39

I would suggest simplifying things to start by not using doto

worlds-endless04:10:27

I'm copying a bunch of code; everything else falls into place nicely, but I can't figure out how to translate that for interop....

didibus04:10:37

(-> agent (.getPrinter) (.pushWriter (OutputStreamWriter. System/out)))

cjohansen07:10:56

I'm having some Java interop trouble. This snippet does not work as expected:

(def watch-service ^java.nio.WatchService (.newWatchService (java.nio.file.FileSystems/getDefault)))

(def path ^java.nio.file.Path (java.nio.file.Paths/get (.toURI ( "resources"))))

(.register
 path
 watch-service
 java.nio.file.StandardWatchEventKinds/ENTRY_MODIFY
 java.nio.file.StandardWatchEventKinds/ENTRY_CREATE
 java.nio.file.StandardWatchEventKinds/ENTRY_DELETE)

;; => IllegalArgumentException: "No matching method register found taking 4 args for class sun.nio.fs.UnixPath"

cjohansen07:10:40

java.nio.file.Path does have this method: register​(WatchService watcher, WatchEvent.Kind<?>... events)

cjohansen07:10:13

if I reduce the number of arguments I instead get this: Cannot cast java.nio.file.StandardWatchEventKinds$StdWatchEventKind to [Ljava.nio.file.WatchEvent$Kind;

schmee07:10:27

@christian767 try

(.register path watch-service
  (into-array WatchEvent.Kind [java.nio.file.StandardWatchEventKinds/ENTRY_MODIFY 
                               java.nio.file.StandardWatchEventKinds/ENTRY_CREATE 
                               java.nio.file.StandardWatchEventKinds/ENTRY_DELETE]))

cjohansen07:10:39

worked 🙂

👍 4
valtteri11:10:39

I’m trying to run Clojure on a Lego robot that has only 64mb of RAM (for fun). I’m actually able to get into repl using java -jar clojure.jar but when I try to use clj I get this nasty error

robot@ev3dev:~$ clj
OpenJDK Client VM warning: INFO: os::commit_memory(0xa9340000, 179044352, 0) failed; error='Not enough space' (errno=12)
#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map 179044352 bytes for committing reserved memory.
# An error report file with more information is saved as:
# /home/robot/hs_err_pid4931.log
Are there some knobs I could tweak to make clj work on low-end hardware or should I just forget about it?

valtteri11:10:06

I installed clj with the Linux installer script from http://clojure.org. I’m not sure if it’s even supposed to work with ARM processors..?

didibus02:10:37

It can, given your JVM runs on arm

didibus02:10:19

And given you have a bash compatible shell

lispyclouds12:10:32

@valtteri afaik, the default max heap is set to something like 256m. Does running something like clj -J-Xmx32m help?

valtteri12:10:19

Nope, it gives the same error

lispyclouds12:10:30

setting both Xms and Xmx to 32m?

lispyclouds12:10:53

if still not, then its beyond me 😞

valtteri12:10:07

Nope, but thanks anyway!

Alex Miller (Clojure team)13:10:33

clj runs 2 JVMs - one to compute the classpath, one to run your repl/app

Alex Miller (Clojure team)13:10:04

There is a min heap fixed for the first one and I suspect it’s too high for you

Alex Miller (Clojure team)13:10:03

You could edit the clojure script and remove the one place with -Xms and see if that works

valtteri13:10:52

I almost know how to use slack.. AWESOME! I removed all -Xms 256mb switches from the script and it got clj running 👍 Thanks @alexmiller But now I think I have some kind of an SSL problem which is in the snippet above

Alex Miller (Clojure team)13:10:00

Sorry, don’t know what that is

valtteri13:10:19

No problem, I’ll try to hack my way around it.

Alex Miller (Clojure team)13:10:46

Might be a mismatch in what TLS level is being used on client vs what is allowed by server

Alex Miller (Clojure team)13:10:35

There is an https.protocols System property you could look at

spfeiffer14:10:21

Someone has an idea why lein fails to download the nrepl:nrepl:jar:0.6.0, clojure-complete:clojure-complete:jar:0.2.5 and viebel:codox-klipse-theme:jar:0.0.5 dependencies from http://clojars.org while all other deps download fine from clojars? So no network issue.

spfeiffer14:10:50

Looking at clojars, they should are there using these coordinates.

Noah Bogart15:10:59

You can edit posts if you need to!

Noah Bogart15:10:13

Long press on mobile or click the 3 dots on desktop/web

spfeiffer16:10:53

Old IRC habits, sorry. Thanks for the reminder.

Noah Bogart16:10:05

Of course! Not everyone knows about it

spfeiffer20:10:00

Solved the issue: The project.clj was setting the clojars URL to . explicitly. Changing that to fixed it, all deps could be found and downloaded.

valtteri14:10:11

I created a POM on my laptop using clj -Spom and now I’m attempting mvn dependency:resolve. It’s giving warnings about not being able to fetch descriptors but it seems to be downloading the deps anyways. Everything just takes super long with this hardware. 😄

valtteri16:10:38

I ended up wrapping clojure and other libs into an uberjar on my mac, shipping it to the robot and running with rlwrap java -jar robo-test-0.1.0.jar. My guess is that the SSL problems have something to do with the custom JDK13 that I’m using. I’ll try next weekend clj with JDK12. Nevertheless, I’m now able to live-code the robot from the REPL and I feel super empowered! 💪

kulminaator16:10:26

i also had ssl problems on arm when i used adoptjdk's version

kulminaator16:10:39

if you do the stuff just for fun then you can try azul's zulu jvm , this one worked as expected out of the box

kulminaator16:10:27

(i ended up going for a 64 bit raspberry linux instead in the end and could use openjdk's official package from ubuntu's repo again, so i don't use zulu anymore)

valtteri16:10:13

Good to know! I’ll probably give zulu a spin.

kwladyka18:10:14

What is right and common name for situation when you validate data and values depend on each other. For example check if date of birth is lower, than date of graduation or password repeat. I am asking, because I am writing article and right name matter for me 🙂 Not sure which one is the right one. I found Coercion idiomatic here https://stackoverflow.com/questions/45188850/is-use-of-clojure-spec-for-coercion-idiomatic but hmm I don’t feel it is the right one.

hiredman19:10:56

It is a constraint, the valid values for date of birth constrain the valid values for date if graduation and vice versa

hiredman19:10:09

Coercion is not that at all. Coercion is changing some value into another

hiredman19:10:22

Calling it a constraint draws analogies with database schema which are often good analogies for spec

👍 4