This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-07-12
Channels
- # announcements (2)
- # beginners (36)
- # boot (6)
- # calva (2)
- # cider (18)
- # clj-kondo (1)
- # cljdoc (2)
- # cljs-dev (2)
- # clojure (130)
- # clojure-boston (1)
- # clojure-brasil (3)
- # clojure-czech (1)
- # clojure-europe (11)
- # clojure-italy (4)
- # clojure-losangeles (37)
- # clojure-nl (9)
- # clojure-seattle (2)
- # clojure-sweden (8)
- # clojure-uk (23)
- # clojurescript (13)
- # core-async (21)
- # cursive (13)
- # data-science (6)
- # datomic (12)
- # emacs (36)
- # figwheel-main (9)
- # fulcro (76)
- # juxt (2)
- # keechma (18)
- # leiningen (4)
- # off-topic (13)
- # pedestal (37)
- # re-frame (21)
- # reitit (2)
- # shadow-cljs (78)
- # spacemacs (23)
- # sql (13)
- # tools-deps (25)
- # uncomplicate (4)
- # unrepl (1)
- # vim (27)
Is someone around using Polilyth on production? https://polylith.gitbook.io/polylith/
I would like to do embedded scripting in Clojure for my clojure program which can be compiled with GraalVM
@markx Assuming you are producing a native executable which no longer has a JVM available (and thus no Clojure compiler), if you have the ability to link your native executable to a JavaScript engine, you could use self-hosted ClojureScript to script things. This seems like a long stretch to get what I'm guessing you want, but thought I'd mention it as being technically feasible.
yeah I thought about migrating my program to cljs, but I feel eval
is just too painful. Also I don’t understand how it’ll work with nrepl and cider and stuff if I use self-hosted ClojureScript.
To be honest, it is not clear to me what you are striving to achieve, and I'm speculating heavily.
hmm I don’t understand which part is not clear. Could you elaborate so I can rephrase my question?
You mentioned GraalVM and embedded scripting... are you using GraalVM to produce a native executable, but want to embed a scripting language into it that uses Clojure's syntax?
Yeah, it’s like other typical embedded scripting, eg c++ and lua. You compile c++ code to a binary, and this binary will load lua files (scripts) at runtime.
I want to use GraalVM to compile my clojure program (host) to a binary, and this binary will load more clojure files (scripts) at runtime.
Currently I just use load-file
to eval those scripts, which is not supported by GraalVM.
Right... that makes sense. So, your binary won't have the JVM available. (It will be native code at that point.)
So, if you want to load a script-based on Clojure syntax, that script will have to be compiled.
I'm just suggesting that one alternative is to embed a JavaScript engine in your binary. If you do that then self-hosted ClojureScript could be used to compile your scripts.
clojurescript is just a program, that takes input and produces ouput, no classes created
For example, Lumo and Planck are binaries, that don't have a JVM. Each has a JavaScript engine embedded / linked in it (V8 for Lumo, and JavaScriptCore for Planck). And each can dynamically compile and execute ClojureScript.
I ultimately would like to make Planck's guts available for native programs that want to embed a "Clojure"-based scripting language: https://github.com/planck-repl/planck/issues/936
This self-hosted/bootstrap cljs sounds very tricky, and I don’t understand all enough to use them.
It is indeed very tricky. If the issue above were implemented, you could just link to such a library instead. 🙂 But, it is not available yet.
an easy action item is : check if you can run some javascript from a compiled graalvm exe
I just can’t help complaining, why can’t cljs just come with the compiler? 😌 Ofc you could argue that on browser you don’t need the compiler anyway so you can save code size. But in my understanding, the one with the compiler should be the default version. :man-shrugging:
look where we are with our supercomputers in a pocket, and still programs are slow and instead of 1mb, they're now gibabytes
I’ll probably rewrite my program in Go and use something else for scripting then. :man-shrugging:
I haven’t really used Planck yet. So assume I port my host program to cljs, then I run it with Planck, and I will be able to load more cljs file at runtime?
I mean, if someone wants a program running on any device, and that program has the ability to load programs, in any language, into it, then that person owns their security goals (or non-goals). Sandbox it if you can, or let anything run (which might be markx's goal -- I don't know)
sure, but there are many cases where you might want a scripting language that only accesses what you allow, see the browsers as a common example
The JVM was originally developed to be run in web browsers, and has a kind of security model associated with it, and you can put restrictions on what it can load and execute if you work enough at it.
I'm not advocating that markx get a JVM running on their phone here, by the way.
I haven’t really used Planck yet. So assume I port my host program to cljs, then I run it with Planck, and I will be able to load more cljs file at runtime?
Does Planck work with shadow-cljs? I imagine I would be using many js/node libs and I probably will want to use shadow-cljs for dev.
No. But. With Planck you'd probably resort to using something like Webpack to extract a NPM library. But if Node support is important to you, Lumo is much better in that regard.
i think the react native people are having a nice workflow with reloading on the phone, so it must be possible, might be worth investigating there
(It doesn't support nREPL, but there is evidently an Emacs mode of some sort to hook into it.)
Yeah termux has node, so it might not be that hard to get lumo running. But again, this is so tricky. So many hacks to do. 🙂
This is why Termux is so great. It makes it painless to setup your phone just like a linux box.
If you just want to run something textual on and Android device, and it doesn't necessarily need to be in Termux, you could fork Replete for Android, and revise its UI from being a REPL to being a textual display of some sort. 🙂
This is why Termux is so great. It makes it painless to setup your phone just like a linux box.
How would you run js
on phone?
Hey guys, I am trying to generate java class for Clojure namespace. In that namespace I have a method which can take string or map depends on user. What should I define :methods
definations of gen-class for that methods ?
@rulz.gupta First off, I'd say "don't do that". In general, a function that can take completely different types for a single argument is poorly designed.
Okay. let me give you more context. My func is wrapping the https://kafka.apache.org/10/javadoc/org/apache/kafka/clients/producer/KafkaProducer.html#send-org.apache.kafka.clients.producer.ProducerRecord- In this producer records takes the generic K,V. How should I solve this.
I can create methods which overload with different types of params. But this K can be object. In some cases, This can be user defined object as well.
Generic types are erased after compilation so that aspect doesn't matter. Both versions of send
take a ProducerRecord
as the first argument. The second send
takes an additional argument. So this is multiple arities, not overloading on the type of a single argument.
If you refactor it to two separate functions, it then becomes easy to generate a class from it. And, yes, in Java you could overload a method to take a String
or a Map
but it's still poor design in general. Constructors are about the only place that's excusable, IMO.
anyone know what it the minimal version of JVM/java for running the actual clojure?
@alexmiller thx! I was wondering, in the release notes of clojure is this stated the requirement binded to java?
Another Java noob question. I heard time ago that jvm licenses has changed. Has this any consequence for clojurians open-source code and or for legacy?
Oracle's JDK license has changed see: https://medium.com/@javachampions/java-is-still-free-2-0-0-6b9aa8d6d244
if i have a collection shaped like this:
[[:foo [:inner1 :inner2] :bar [:inner3 :inner4]]
and i want to transform this into
[[:foo :inner1] [:foo :inner2] [:bar :inner3] [:bar :inner4]]
is there a more elegant way to do this rather than a reduce?
you can't really create the right structure with mapcat
otoh, maybe @noisesmith is right and reduce is probably the easiest-to-understand function
(let [data [:foo [:inner1 :inner2] :bar [:inner3 :inner4]]]
(for [[x ys] (partition 2 data)
y ys]
[x y]))
(mm/search [[:foo [:inner1 :inner2]] [:bar [:inner3 :inner4]]]
(scan [?k (scan ?xs)])
[?k ?xs])
=>
([:foo :inner1] [:foo :inner2] [:bar :inner3] [:bar :inner4])
With that you've introduced the meander DSL, making it less elegant and readable IMO.
here a deprecated function is still used: https://github.com/clojure/clojure/blob/653b8465845a78ef7543e0a250078eea2d56b659/src/clj/clojure/test/junit.clj#L118
Has anyone used VisualVM for profiling memory consumption? I need to profile memory consumption of a namespace but it seems like VisualVM can not find my namespaces. How can I make them visible?
a namespace contains a hash from symbols to vars, you could follow the recursive usage of memory from that root into the objects in the vars
one hack is to replace a suspect hash-map with a defrecord, the profiler makes it easy to check the nested memory usage of that record's class
"memory cosumption of a namepsace" is unlikely to ever show up in a profiler how ever you profile things
so "I need to profile memory consumption of a namespace" sounds like trying to force clojure namespaces in to a java class shaped hole, which they don't
Oh I see, so defrecording suspect data structures is a way to go, thanks!