Fork me on GitHub
#babashka
<
2021-03-04
>
souenzzo13:03:14

I remember some feature to invoke the JVM with bb, but I can't find it's docs. My use case is: use bb as launch script for my main application. The main reason for doing that is to get some parameters from aws ssm and use them as ENV (that can't be done inside the JVM)

borkdude13:03:47

@souenzzo

$ bb -e "(println (:out @(babashka.deps/clojure '[-M -e (System/getenv \"FOO\")] {:env {'FOO 'BAR} :out :string})))"
"BAR"

👍 3
borkdude13:03:32

Note that you will have to merge (System/getenv) yourself if you want to pass other env vars from the parent process if you provide :env

souenzzo13:03:21

babashka.deps/clojure ! Ok. Full control over env also nice 🙂

borkdude13:03:48

Yes, it is the same API as babashka.process but focused on invoking clojure

borkdude13:03:54

So for more docs you can look at that lib

andarp16:03:01

Will babashka work with external packages like eg https://github.com/clojure/data.csv

borkdude16:03:35

@anders152 Even better: clojure.data.csv is built into babashka

andarp16:03:33

Oh, that’s great for my use case! But what about something that only exists on e g clojars?

borkdude16:03:49

We have a (non-exhaustive) list of compatible libraries here: https://github.com/babashka/babashka/blob/master/doc/projects.md

❤️ 3
andarp16:03:39

I’m still not sure I fully understand exactly what babashka is. Is it a separate runtime from the jvm? Or some strange hybrid?

borkdude16:03:17

@anders152 Good question. Babashka is similar to the JVM, but it supports a subset of both the JVM and Clojure. Usually enough for scripting, but there are some things missing like deftype.

borkdude16:03:41

It is compiled to native using GraalVM native-image. Code evaluation is done using a Clojure interpreter.

borkdude16:03:16

Benefits for scripting: fast startup, built-in libraries

borkdude16:03:32

If babashka is not sufficient you can often directly run your code on the JVM instead

andarp16:03:13

I was directed here after asking how to best run Clojure scripts from a shell for eg file cleanup tasks. And I think in most cases this does fit the bill!

andarp16:03:03

I just want to understand the rationale and history somewhat when I’m getting into a new tool. Learning Clojure and not having a JVM background is daunting enough sometimes - there’s a lot of “I guess this just works but I don’t really understand it” for me.

borkdude16:03:58

Feel free to ask anything here, we're friendly to beginners (at least, we should, if not, I will ban them :P)

andarp16:03:05

But one thing I do notice with Clojure stuff is that’s everything seems to exist or be done a certain way for Good Reasons grounded in real world use and pragmatism, so I feel quite calm in just accepting things as they are and learning as I go.

andarp16:03:51

Yes, I have found nothing but kindness and patience when asking questions here. Lovely environment to learn in :)