Fork me on GitHub
#clojure
<
2019-07-12
>
wcalderipe01:07:18

Is someone around using Polilyth on production? https://polylith.gitbook.io/polylith/

✔️ 4
markx02:07:11

Is there something like benzap/eden but using clojure’s syntax?

markx02:07:05

I would like to do embedded scripting in Clojure for my clojure program which can be compiled with GraalVM

mfikes02:07:58

@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.

markx02:07:01

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.

mfikes02:07:30

To be honest, it is not clear to me what you are striving to achieve, and I'm speculating heavily.

markx02:07:05

hmm I don’t understand which part is not clear. Could you elaborate so I can rephrase my question?

mfikes02:07:20

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?

carkh02:07:10

mhh i wonder if their new javascript implementation works in such an environment

carkh02:07:18

doubt it tbh

mfikes02:07:27

(Meaning, a scripting language that still works in the native executable.)

markx02:07:39

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.

markx02:07:41

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.

markx02:07:10

Currently I just use load-file to eval those scripts, which is not supported by GraalVM.

mfikes02:07:22

Right... that makes sense. So, your binary won't have the JVM available. (It will be native code at that point.)

carkh02:07:51

using jvm clojure for that is a security nightmare

markx02:07:19

Do you have a better suggestion?

carkh02:07:13

i'd go with any scripting language that cannot escape the api provided to it

mfikes02:07:57

So, if you want to load a script-based on Clojure syntax, that script will have to be compiled.

carkh02:07:00

and impossible =)

carkh02:07:38

i would check if you can make javascript work

mfikes02:07:45

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.

carkh02:07:48

then maybe compile cljs to it

carkh02:07:02

or even not self hosted

carkh02:07:44

clojurescript is just a program, that takes input and produces ouput, no classes created

mfikes02:07:51

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.

mfikes02:07:31

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

markx02:07:00

This self-hosted/bootstrap cljs sounds very tricky, and I don’t understand all enough to use them.

mfikes02:07:43

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.

carkh02:07:59

an easy action item is : check if you can run some javascript from a compiled graalvm exe

markx02:07:51

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:

mfikes02:07:37

Hah. We still live in a world where delivered executable size matters.

mfikes02:07:53

Maybe in 10–15 years, self-hosted ClojureScript will be the default. 🙂

carkh02:07:20

nah runtime weight will increase as fast as bandwidth

carkh02:07:48

look where we are with our supercomputers in a pocket, and still programs are slow and instead of 1mb, they're now gibabytes

markx02:07:52

I’ll probably rewrite my program in Go and use something else for scripting then. :man-shrugging:

carkh02:07:23

the question is, why do you need a compiled program ?

markx02:07:32

because it’s a tui program, and I want to run it on my phone using Termux.

carkh02:07:30

i'd go with self-hosted clojurescript then, an easy choice

mfikes02:07:41

Hrm. Just compile Planck for your target and run it in there.

markx02:07:42

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?

carkh02:07:52

or that yes

mfikes02:07:05

Then you could write your TUI in ClojureScript.

carkh02:07:38

the security aspect though ...

andy.fingerhut02:07:31

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)

mfikes02:07:46

Maybe the program is just for Ke's use?

carkh02:07:48

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

andy.fingerhut02:07:58

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.

andy.fingerhut02:07:46

I'm not advocating that markx get a JVM running on their phone here, by the way.

carkh02:07:18

already has one on the sim card !

mfikes02:07:11

Just install Clojure in Termux and call it a day. 🙂

carkh02:07:22

and emacs with cider, then just go C-c M-J to jack in clojruescript =D

markx02:07:42

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?

mfikes02:07:59

Sure, Planck ships with the self-hosted ClojureScript compiler.

mfikes02:07:07

Same is true for Lumo.

markx02:07:49

So I just use Planck when I run my program. And for dev I still use normal cljs?

mfikes02:07:40

Essentially, yes.

markx02:07:39

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.

mfikes02:07:02

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.

mfikes02:07:21

Lumo essentially is Node.

carkh02:07:43

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

markx03:07:56

But Lumo doesn’t work with nrepl and stuff, right?

markx03:07:29

I’m very confused. I might be missing something here.

markx03:07:21

Can I use nrepl and cider and stuff if my app needs to run with lumo?

mfikes03:07:14

You can connect work with Lumo from Emacs, if that's what you are asking

mfikes03:07:49

(It doesn't support nREPL, but there is evidently an Emacs mode of some sort to hook into it.)

mfikes03:07:30

It looks like Lumo isn't built for Termux, so you'd need to sort that out.

markx03:07:24

hmm I don’t use Emacs. I use vim. So far I’ve been using fireplace with nrepl.

markx03:07:36

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. 🙂

markx03:07:08

Anyway, thanks for all the info!

carkh03:07:17

well running a terminal in a phone is already more than a step into hack land

markx03:07:03

This is why Termux is so great. It makes it painless to setup your phone just like a linux box.

mfikes03:07:56

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. 🙂

markx03:07:03

This is why Termux is so great. It makes it painless to setup your phone just like a linux box.

carkh03:07:07

use pure clojurescript, have your script writers compile theirs to javascript

carkh03:07:01

so now you have two scripting languages ! cljs and js

Ahmed Hassan04:07:25

How would you run js on phone?

kartik715305:07:55

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 ?

seancorfield06:07:42

@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.

👍 4
kartik715306:07:54

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.

kartik715306:07:26

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.

seancorfield06:07:49

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.

seancorfield06:07:48

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.

dmaiocchi11:07:11

anyone know what it the minimal version of JVM/java for running the actual clojure?

dmaiocchi11:07:42

suppose I have a really old legacy systems where as usual nobody want/can update

dmaiocchi11:07:08

what could be the requirements in term of java/jvm for running the current clojure

dmaiocchi11:07:14

(thinking in term of backward compatibilty..)

dmaiocchi11:07:50

@alexmiller thx! I was wondering, in the release notes of clojure is this stated the requirement binded to java?

Alex Miller (Clojure team)11:07:39

Probably a better reference

❤️ 4
dmaiocchi13:07:46

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?

lambdalove 4
ghadi13:07:30

jvm license has not changed, still GPL

dmaiocchi13:07:25

Ah OK thx. So it is Java license but OpenJdk is still free

👍 8
lmergen17:07:24

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?

lmergen17:07:56

i'm thinking there must be a zip or something solution but i'm not seeing it atm

dmaiocchi20:07:13

Why you find reduce not élégant just from curiosity pov

dmaiocchi20:07:45

Afaik map, reduce,filter àre quite the basic transducers

noisesmith17:07:00

it's straightforward with reduce

👍 8
clj 4
tavistock17:07:59

partition and mapcat could make a none reduce version

✔️ 4
noisesmith17:07:37

you can't really create the right structure with mapcat

isak17:07:12

you can use for after the partition

tavistock17:07:43

(mapcat (fn [[x ys]] (map (fn [y] [x y]) ys)) (patition 2 data))

lmergen17:07:13

oh that's nice

lmergen17:07:45

otoh, maybe @noisesmith is right and reduce is probably the easiest-to-understand function

isak17:07:20

(let [data [:foo [:inner1 :inner2] :bar [:inner3 :inner4]]]
  (for [[x ys] (partition 2 data)
        y ys]
    [x y]))

tavistock17:07:15

(for combinotronics for is really nice)

lmergen17:07:21

maybe this is actually a task for specter / meander / something else

lmergen18:07:01

(mm/search [[:foo [:inner1 :inner2]] [:bar [:inner3 :inner4]]]
            (scan [?k (scan ?xs)])
            [?k ?xs])
=> ([:foo :inner1] [:foo :inner2] [:bar :inner3] [:bar :inner4])

lmergen18:07:59

(this is meander)

the2bears18:07:49

With that you've introduced the meander DSL, making it less elegant and readable IMO.

8
seancorfield18:07:43

I certainly find the for above much easier to read than meander.

16
lmergen18:07:26

I agree the for implementation is the nicest

lmergen18:07:44

or at the very least more simple

borkdude18:07:44

just fyi, it's not bothering me personally 😉

diego.videco18:07:36

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?

noisesmith18:07:02

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

noisesmith18:07:28

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

hiredman18:07:37

"memory cosumption of a namepsace" is unlikely to ever show up in a profiler how ever you profile things

hiredman18:07:59

namespaces are mostly collections of static data which is mostly by nature small

hiredman18:07:21

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

diego.videco18:07:25

Oh I see, so defrecording suspect data structures is a way to go, thanks!