Babashka is implemented using the Small
Clojure Interpreter. This means that a snippet or script is not
compiled to JVM bytecode, but executed form by form by a runtime which
implements a substantial subset of Clojure. Babashka is compiled to a
native binary using GraalVM. It comes
with a selection of built-in namespaces and functions from Clojure and
other useful libraries. The data types (numbers, strings, persistent
collections) are the same. Multi-threading is supported (pmap
,
future
).
Differences with Clojure:
-
A pre-selected set of Java classes are supported. You cannot add Java classes at runtime.
-
Interpretation comes with overhead. Therefore loops are slower than in Clojure on the JVM. In general interpretation yields slower programs than compiled programs.
-
No
deftype
,definterface
and unboxed math. -
defprotocol
anddefrecord
are implemented using multimethods and regular maps. Ostensibly they work the same, but under the hood there are no Java classes that correspond to them. -
Currently
reify
works only for one class at a time -
The
clojure.core.async/go
macro is not (yet) supported. For compatibility it currently maps toclojure.core.async/thread
. More info here.
A list of projects (scripts, libraries, pods and tools) known to work with babashka.
Pods are programs that can be used as a Clojure library by babashka. Documentation is available in the library repo.
AWS Lambda runtime doesn’t support signals, therefore babashka has to
disable handling of SIGINT and SIGPIPE. This can be done by setting
BABASHKA_DISABLE_SIGNAL_HANDLERS
to true
.
-
Writing Clojure on the Command Line with Babashka, a talk by Nate Jones.
-
Using Clojure in Command Line with Babashka, a blog article by Kari Marttila.
-
Babashka and GraalVM; taking Clojure to new places, a talk by Michiel Borkent at Clojure/NYC.
-
Import a CSV into Kafka, using Babashka by Dave Martin
-
Learning about babashka, a blog article by Andrew Montalenti
-
Babashka Pods presentation by Michiel Borkent at the Dutch Clojure Meetup.
-
AWS Logs using Babashka, a blog published by Toyokumo.
-
The REPL podcast Michiel Borkent talks about clj-kondo, Jet, Babashka, and GraalVM with Daniel Compton.
-
Implementing an nREPL server for babashka: impromptu presentation by Michiel Borkent at the online Dutch Clojure Meetup
-
ClojureScript podcast with Jacek Schae interviewing Michiel Borkent
-
Babashka talk at ClojureD (slides) by Michiel Borkent
-
Babashka: a quick example by Malcolm Sparks
-
Clojure Start Time in 2019 by Stuart Sierra
-
Advent of Random Hacks by Arne Brasseur
-
Clojure in the Shell by Arne Brasseur
-
Clojure Tool by Eric Normand
Before new libraries or classes go into the standardly distributed babashka binary, these evaluation criteria are considered:
-
The library or class is useful for general purpose scripting.
-
Adding the library or class would make babashka more compatible with Clojure libraries relevant to scripting.
-
The library cannot be interpreted by with babashka using
--classpath
. -
The functionality can’t be met by shelling out to another CLI or can’t be written as a small layer over an existing CLI (like
babashka.curl
) instead. -
The library cannot be implemented a pod.
If not all of the criteria are met, but adding a feature is still useful
to a particular company or niche, adding it behind a feature flag is
still a possibility. This is currently the case for next.jdbc
and the
PostgresQL
and HSQLDB
database drivers. Companies interested in
these features can compile an instance of babashka for their internal
use. Companies are also free to make forks of babashka and include their
own internal libraries. If their customized babashka is interesting to
share with the world, they are free to distribute it using a different
binary name (like bb-sql
, bb-docker
, bb-yourcompany
, etc.). See
the feature flag documentation and the
implementation of the existing feature flags
(example
commit).
In the future we will migrate examples from this README to the babashka book. This is work in progress and you are welcome to contribute.
-
adgoji for financial support
-
CircleCI for CI and additional support
-
Nikita Prokopov for the logo
-
contributors and other users posting issues with bug reports and ideas
This project exists thanks to all the people who contribute. [Contribute].