Skip to content

Instantly share code, notes, and snippets.

@dvliman
Forked from cldwalker/spike-day-02-03-20.md
Created February 9, 2020 20:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dvliman/2678573cb8d27490f2d065b27bf95725 to your computer and use it in GitHub Desktop.
Save dvliman/2678573cb8d27490f2d065b27bf95725 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