r/Clojure • • Nov 29 '19

Scripting in Clojure, many great options!

I'd recommend looking at all the awesome scripting options for Clojure:

Honestly, scripting is just a solved problem for Clojure in my opinion. At this point. There's even too many good options probably.

My current favorite is Joker. I find it is the most bash like in that the standard library is very small, so just like on bash, you end up delegating to forked processes using sh. Works on Windows, Linux and Mac alike. Single binary.

Inlein is best if your script needs a ton of Clojure dependencies.

Babashka is quite promising, it competes with Joker, but windows support isn't great yet, and it is still alpha. But it has great potential.

Closh is just awesome. It is a literal replacement for bash, in that it is a full shell implemented in Clojure/Script. I really want to see it evolve and get super stable and feature complete. I'd love to make it my default shell instead of zsh.

Lumo and Planck are both great ClojureScript repls that can be used for scripts. Since I'm less familiar with Node and JavaScriptCore APIs I don't tend to use them as much. Also, installing Node is cumbersome, and Planck doesn't support windows. So I've stopped using them for scripting. But great options if you know the JS world a lot.

The last one can be a good replacement for inlein. Similarly, it's a good option if you need a lot of extra Clojure dependencies. It's a clever hack that lets a simple sh script self bootstrap Clojure code within itself and pull in dependencies from tools.deps. There were times when I needed to do more maneuvering to get it working, but it only needs sh and Clojure, which is nice.

73 Upvotes

33 comments sorted by

View all comments

Show parent comments

2

u/Borkdude Dec 01 '19

Haven't tried Babashka so I don't know if that's also the case with it or not.

Babashka tries to be as compatible with JVM Clojure as it can, so you can easily switch between the two. E.g. see this portable script:

https://github.com/borkdude/babashka/blob/master/README.md#portable-tree-command

1

u/Eno6ohng Dec 01 '19

While you are here, a couple of unrelated questions if I may:

  1. Can Babashka be extended to run in a closh-like mode? I like Closh, but JVM still feels too heavy for a bash killer. Should it be done in a separate project? A fork of Closh maybe?

  2. Why Babashka doesn't have a repl client? To avoid overhead?

  3. Can Babashka support extra dependencies via deps.edn git provider?

2

u/Borkdude Dec 01 '19
  1. Babashka is built using the sci library which can be used as an "eval" for GraalVM:
    https://github.com/borkdude/sci

    Currently closh is working towards a native build using sci.

  2. You can use rlwrap nc 127.0.0.1 1666 as a socket-repl client, but personally I feel connecting from an editor and evaluating expressions gives a much better experience. What's also an option is to develop a script using normal JVM clojure first and then see if it runs with babashka, tweaking it where needed. Babashka supports reader conditionals and takes the first :bb branch, or :default otherwise.

  3. You can use external scripts using load-file. I am considering loading files from classpaths generated by deps.edn, but it's not there yet.

1

u/Eno6ohng Dec 01 '19

Currently closh is working towards a native build using sci.

Awesome! The related issues for others reading this to follow:

personally I feel connecting from an editor and evaluating expressions gives a much better experience.

In general, I agree; at the same time, when trying out bb for the first time I was somewhat confused that I don't see an option to start a repl, like in all other clojure distributions. Not a big problem of course, just a minor 'principle of least surprise'-related quirk/feature.

I am considering loading files from classpaths generated by deps.edn, but it's not there yet.

Cool! I'll be definitely following the project more closely. Thank you! (and thanks to didibus for bringing extra attention to all these projects)

3

u/Borkdude Dec 01 '19

when trying out bb for the first time I was somewhat confused that I don't see an option to start a repl,

Might be a nice feature to add, I agree. I'll make an issue for it.

1

u/Borkdude Dec 08 '19

when trying out bb for the first time I was somewhat confused that I don't see an option to start a repl

This feature has now been added to babashka:

https://github.com/borkdude/babashka/releases/tag/v0.0.39

1

u/Eno6ohng Dec 08 '19

Yay, thanks!