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

3

u/Eno6ohng Nov 30 '19

I wish Joker supported the usual nrepl/cider tooling and had (out of the box) the ability to create go-like single-file executables (basically a bundle of joker executable and clj source files to interpret). That'd make it the best way to start with clojure imo.

1

u/didibus Nov 30 '19

Eh 😅, that's a lot to ask, but yeah that would be neat.

It does support a socket repl and has a basic REPL at the command line. Which mean you can use Atom with Chlorine for it. Or Emacs with inf-clojure.

I believe the nRepl and co machinery makes use of Java facilities. So I think that would make a port to Joker hard.

I like that bundling idea. I feel it's possible there exist already a bundler that could do that. Take arbitrary files and pack them in a single executable with one file being selected as the main entry.

1

u/Eno6ohng Dec 01 '19

I believe the nRepl and co machinery makes use of Java facilities. So I think that would make a port to Joker hard.

Yeah, unfortunately. It also uses parallel features that are lacking in Joker.

Take arbitrary files and pack them in a single executable with one file being selected as the main entry.

Yeah, basically just an archive with executable headers, similar to how people bundle jars sometimes. Even if scripting per se can be considered an (almost) solved problem, it still requires quite a bit of env setup; the ability to create a single portable binary would solve this, and also a 'getting started' guide could be reduced to like 3 lines ("download this, save your file, run this command; boom that's all!"), which is neat for newcomers.

1

u/Eno6ohng Dec 01 '19

Soo, actually I think I'm totally wrong on this one, the best way to do it is to use babashka + any 3rd-party bundling tool, like https://makeself.io or something similar. You can "build" a single binary in a couple of minutes, and potentionally you can use jvm clojure for development phase so you have all the cider goodies (that won't be too friendly for newcomers though due to the differences between dialects). Also another problem is that babashka doesn't ship ARM binaries (yet?) so you can't put your clojure scripts (not clojurescripts, clojure _ scripts) on your raspberry (yet), but graal support is already there as far as I understand, so it should be doable... in any case graal+sci for sure seems like THE best way forward, with git deps support and overall better tooling it would be a totally viable option not just for scripting, but for any small(ish) apps as well.

The only thing I'm left wondering about is whether Oracle would get to precompiling the whole maven central someday, because dealing with java dependencies on yourself is not that much fun...