Skip to content

Instantly share code, notes, and snippets.

@cldwalker
Last active June 19, 2024 04:24
Show Gist options
  • Save cldwalker/663c3e1a82dc2ccf9e53eb8f45d08fc4 to your computer and use it in GitHub Desktop.
Save cldwalker/663c3e1a82dc2ccf9e53eb8f45d08fc4 to your computer and use it in GitHub Desktop.
GraalVM dive in Clojure at work

Spike

I looked into the state of GraalVM and Clojure and wrote some small work-related scripts.

GraalVM Build Tools

GraalVM CLIs

I looked through and tried a number of CLIs and found the following three to be the most useful.

jet

https://github.com/borkdude/jet is a handy tool for slicing and dicing json or edn. It is similar in functionality to what jq provides for json but with possibly more power and a clojure syntax.

I found jet has a sweet spot for exploring and drilling into api responses. I was able to use a github api to print the PR for a commit and open it. Here is that script:

$ curl -H 'Accept: application/vnd.github.groot-preview+json' -s 'https://api.github.com/repos/stedolan/jq/commits/0fd0f0b00dc4c3df97286de241ab400cf2f8c97c/pulls' | jet --from json --keywordize --query 'first :html_url' |xargs open

clojurl

https://github.com/taylorwood/clojurl is a curl-like tool that can make web requests. Unlike curl, the response come back as a data structure and can be easily manipulated with something like jet. This seems it could be useful when working with APIs.

babashka

https://github.com/borkdude/babashka is the most promising tool as it provides a graalvm speed interpreter for a subset of Clojure. This tool can be used for concise one-line scripts or more impressively for Clojure scripts to replace shell scripts. It supports a number of standard libraries including tools.cli for option parsing, can make https requests and comes with a repl.

In order to build something useful for work and to test how useful babashka is, I wrote this script which expands on the above one-liner with jet by providing authentication, error handling and git repository detection. For command usage see the readme. I found the development experience to be super helpful as I could try small things in the babashka repl as well as rerun the script at lightning speed.

Additional CLIs

These are graalvm based clis that look interesting:

Takeaways

Graalvm tooling for Clojure has gotten noticeably better the past 12 months. Clojure community is starting to build some useful clis with graalvm. Writing fast Clojure clis is easy to do with clj.native-image. However the compile times are slow and distribution for a team takes additional effort. To overcome those pains you can use babashka for faster development cycles and an easier distribution story.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment