OSS updates March and April 2025

In this post I'll give updates about open source I worked on during March and April 2025.

To see previous OSS updates, go here.

Sponsors

I'd like to thank all the sponsors and contributors that make this work possible. Without you the below projects would not be as mature or wouldn't exist or be maintained at all! So a sincere thank you to everyone who contributes to the sustainability of these projects.

gratitude

Current top tier sponsors:

Open the details section for more info about sponsoring.

Sponsor info

If you want to ensure that the projects I work on are sustainably maintained, you can sponsor this work in the following ways. Thank you!

On to the projects that I've been working on!

Blog posts

I blogged about an important improvement in babashka regarding type hints here.

Interviews

Also I did an interview with Jiri from Clojure Corner by Flexiana, viewable here.

Updates

Here are updates about the projects/libraries I've worked on in the last two months.

  • babashka: native, fast starting Clojure interpreter for scripting.

    • Improve Java reflection based on provided type hints (read blog post here)
    • Add compatibility with the fusebox library
    • Fix virtual ThreadBuilder interop
    • Add java.util.concurrent.ThreadLocalRandom
    • Add java.util.concurrent.locks.ReentrantLock
    • Add classes:
      • java.time.chrono.ChronoLocalDate
      • java.time.temporal.TemporalUnit
      • java.time.chrono.ChronoLocalDateTime
      • java.time.chrono.ChronoZonedDateTime
      • java.time.chrono.Chronology
    • #1806: Add cheshire.factory namespace (@lread)
    • Bump GraalVM to 24
    • Bump SCI to 0.9.45
    • Bump edamame to 1.4.28
    • #1801: Add java.util.regex.PatternSyntaxException
    • Bump core.async to 1.8.735
    • Bump cheshire to 6.0.0
    • Bump babashka.cli to 0.8.65
  • clerk: Moldable Live Programming for Clojure

    • Replace tools.analyzer with a more light-weight analyzer which also adds support for Clojure 1.12
  • squint: CLJS syntax to JS compiler

    • #653: respect :context expr in compile-string
    • #657: respect :context expr in set! expression
    • #659: fix invalid code produced for REPL mode with respect to return
    • #651 Support :require + :rename + allow renamed value to be used in other :require clause
    • Fix #649: reset ns when compiling file and fix initial global object
    • Fix #647: emit explicit null when written in else branch of if
    • Fix #640: don't emit anonymous function if it is a statement (@jonasseglare)
    • Fix #643: Support lexicographic compare of arrays (@jonasseglare)
    • Fix #602: support hiccup-style shorthand for id and class attributes in #jsx and #html
    • Fix #635: range fixes
    • Fix #636: add run!
    • defclass: elide constructor when not provided
    • Fix #603: don't emit multiple returns
    • Drop constructor requirement for defclass
  • clj-kondo: static analyzer and linter for Clojure code that sparks joy.

    • #2522: support :config-in-ns on :missing-protocol-method
    • #2524: support :redundant-ignore on :missing-protocol-method
    • #1292: NEW linter: :missing-protocol-method. See docs
    • #2512: support vars ending with ., e.g. py. according to clojure analyzer
    • #2516: add new --repro flag to ignore home configuration
    • #2493: reduce image size of native image
    • #2496: Malformed deftype form results in NPE
    • #2499: Fix (alias) bug (@Noahtheduke)
    • #2492: Report unsupported escape characters in strings
    • #2502: add end locations to invalid symbol
    • #2511: fix multiple parse errors caused by incomplete forms
    • document var-usages location info edge cases (@sheluchin)
    • Upgrade to GraalVM 24
    • Bump datalog parser
    • Bump built-in cache
  • SCI: Configurable Clojure/Script interpreter suitable for scripting

    • Fix #957: sci.async/eval-string+ should return promise with :val nil for ns form rather than :val <Promise>
    • Fix #959: Java interop improvement: instance method invocation now leverages type hints
    • Fix #942: improve error location of invalid destructuring
    • Add volatile? to core vars
    • Fix #950: interop on local in CLJS
    • Bump edamame to 1.4.28
  • quickdoc: Quick and minimal API doc generation for Clojure

    • Fix #32: fix anchor links to take into account var names that differ only by case
    • Revert source link in var title and move back to <sub>
    • Specify clojure 1.11 as the minimal Clojure version in deps.edn
    • Fix macro information
    • Fix #39: fix link when var is named multiple times in docstring
    • Upgrade clj-kondo to 2025.04.07
    • Add explicit org.babashka/cli dependency
  • CLI: Turn Clojure functions into CLIs!

    • #119: format-table now formats multiline cells appropriately (@lread)
    • Remove pom.xml and project.clj for cljdoc
    • #116: Un-deprecate :collect option to support custom transformation of arguments to collections (@lread)
    • Support :collect in :spec
  • process: Clojure library for shelling out / spawning sub-processes

    • #163, #164: Program resolution strategy for exec and Windows now matches macOS/Linux/PowerShell (@lread)
    • Fix memory leak by executing shutdown hook when process finishes earlier than VM exit (@maxweber)
  • html: Html generation library inspired by squint's html tag

    • Fix #3: allow dynamic attribute value: (html [:a {:a (+ 1 2 3)}])
    • Fix #9: shortcuts for id and classes
  • cherry: Experimental ClojureScript to ES6 module compiler

    • Add cljs.pprint/pprint
    • Add add-tap
    • Bump squint compiler common which brings in new #html id and class shortcuts + additional features and optimizations, such as an optimization for aset
  • nbb: Scripting in Clojure on Node.js using SCI

    • Add better Deno + jsr: dependency support, stay tuned.
  • instaparse-bb: Use instaparse from babashka

  • edamame: Configurable EDN/Clojure parser with location metadata

    • #117: throw on triple colon keyword
  • fs - File system utility library for Clojure

    • #141: fs/match doesn't match when root dir contains glob or regex characters in path
    • #138: Fix fs/update-file to support paths (@rfhayashi)
  • sql pods: babashka pods for SQL databases

    • Upgrade to GraalVM 23, fixes encoding issue with Korean characters

Other projects

These are (some of the) other projects I'm involved with but little to no activity happened in the past month.

Click for more details - [rewrite-edn](https://github.com/borkdude/rewrite-edn): Utility lib on top of - [deps.clj](https://github.com/borkdude/deps.clj): A faithful port of the clojure CLI bash script to Clojure - [scittle](https://github.com/babashka/scittle): Execute Clojure(Script) directly from browser script tags via SCI - [rewrite-clj](https://github.com/clj-commons/rewrite-clj): Rewrite Clojure code and edn - [pod-babashka-go-sqlite3](https://github.com/babashka/pod-babashka-go-sqlite3): A babashka pod for interacting with sqlite3 - [tools-deps-native](https://github.com/babashka/tools-deps-native) and [tools.bbuild](https://github.com/babashka/tools.bbuild): use tools.deps directly from babashka - [http-client](https://github.com/babashka/http-client): babashka's http-client
- [http-server](https://github.com/babashka/http-server): serve static assets - [bbin](https://github.com/babashka/bbin): Install any Babashka script or project with one comman - [sci.configs](https://github.com/babashka/sci.configs): A collection of ready to be used SCI configs. - Added a configuration for `cljs.spec.alpha` and related namespaces - [qualify-methods](https://github.com/borkdude/qualify-methods) - Initial release of experimental tool to rewrite instance calls to use fully qualified methods (Clojure 1.12 only0 - [neil](https://github.com/babashka/neil): A CLI to add common aliases and features to deps.edn-based projects.
- [tools](https://github.com/borkdude/tools): a set of [bbin](https://github.com/babashka/bbin/) installable scripts - [sci.nrepl](https://github.com/babashka/sci.nrepl): nREPL server for SCI projects that run in the browser - [babashka.json](https://github.com/babashka/json): babashka JSON library/adapter - [squint-macros](https://github.com/squint-cljs/squint-macros): a couple of macros that stand-in for [applied-science/js-interop](https://github.com/applied-science/js-interop) and [promesa](https://github.com/funcool/promesa) to make CLJS projects compatible with squint and/or cherry. - [grasp](https://github.com/borkdude/grasp): Grep Clojure code using clojure.spec regexes - [lein-clj-kondo](https://github.com/clj-kondo/lein-clj-kondo): a leiningen plugin for clj-kondo - [http-kit](https://github.com/http-kit/http-kit): Simple, high-performance event-driven HTTP client+server for Clojure. - [babashka.nrepl](https://github.com/babashka/babashka.nrepl): The nREPL server from babashka as a library, so it can be used from other SCI-based CLIs - [jet](https://github.com/borkdude/jet): CLI to transform between JSON, EDN, YAML and Transit using Clojure - [pod-babashka-fswatcher](https://github.com/babashka/pod-babashka-fswatcher): babashka filewatcher pod - [lein2deps](https://github.com/borkdude/lein2deps): leiningen to deps.edn converter - [cljs-showcase](https://github.com/borkdude/cljs-showcase): Showcase CLJS libs using SCI - [babashka.book](https://github.com/babashka/book): Babashka manual - [pod-babashka-buddy](https://github.com/babashka/pod-babashka-buddy): A pod around buddy core (Cryptographic Api for Clojure). - [gh-release-artifact](https://github.com/borkdude/gh-release-artifact): Upload artifacts to Github releases idempotently - [carve](https://github.com/borkdude/carve) - Remove unused Clojure vars - [4ever-clojure](https://github.com/oxalorg/4ever-clojure) - Pure CLJS version of 4clojure, meant to run forever! - [pod-babashka-lanterna](https://github.com/babashka/pod-babashka-lanterna): Interact with clojure-lanterna from babashka - [joyride](https://github.com/BetterThanTomorrow/joyride): VSCode CLJS scripting and REPL (via [SCI](https://github.com/babashka/sci)) - [clj2el](https://borkdude.github.io/clj2el/): transpile Clojure to elisp - [deflet](https://github.com/borkdude/deflet): make let-expressions REPL-friendly! - [deps.add-lib](https://github.com/borkdude/deps.add-lib): Clojure 1.12's add-lib feature for leiningen and/or other environments without a specific version of the clojure CLI

Published: 2025-05-02

Tagged: clojure oss updates

Babashka Java interop, reflection and type hints

Consider the following Clojure code:

(def thread-pool (java.util.concurrent.Executors/newCachedThreadPool))
(def fut (.submit thread-pool (fn [] 3)))
@fut ;;=> ?

I didn't use any type hints, but the names of the vars should give you an idea what's happening:

  • a thread pool is created
  • a piece of work in the form of a function is submitted
  • the thread pool returns a future which we can dereference to do a blocking wait and get the result.

What result would you expect this program to give? My initial guess would be 3.

However, in babashka the result would sometimes be nil (version 1.12.199 on macOS Apple silicon does for example). I've seen this happen in JVM Clojure too in CI (given no type hints, and thus relying on Clojure reflection). I discovered this problem when trying to make bb run the fusebox library and executing its test suite in CI using babashka.

What's the mechanism behind this flakiness? The .submit method in the snippet above is overloaded. When Clojure is doing reflection, it finds the most suitable method for .submit given the instance object and the arguments. In this case the type of the instance object (the thread-pool value) is of type java.util.concurrent.ThreadPoolExecutor, which has three overloads (inherited from java.util.concurrent.AbstractExecutorService):

  • public Future<?> submit(Runnable task)
  • public <T> Future<T> submit(Runnable task, T result)
  • public <T> Future<T> submit(Callable<T> task)

Only two of those match the number of arguments we used in the snippet, so we are left with:

  • public Future<?> submit(Runnable task)
  • public <T> Future<T> submit(Callable<T> task)

Clojure's reflector will try to see if the argument type to .submit matches any of these methods. Since we called it with a function, in this case it matches both. If multiple methods match, it will try to pick the most specific method using clojure.lang.Compiler/subsumes. Since Runnable and Callable are two distinct types (one doesn't inherit from the other), Clojure's reflector just returns the first method it deemed most suitable. So it could be either method. The java documentation mentions the submit method with the Runnable argument first, but this isn't necessarily the order in which Java reflection will list those methods. I have found out that the order may even be indeterministic over multiple CI runs and JVM implementations or versions. What the exact cause of this indeterminism is, I don't know, but I found out the hard way that it exists 😅.

So when does the above snippet return nil? When the Runnable overload is chosen, since Runnable is an interface with run method that returns void (which is nil in Clojure). Let me show this using a snippet that uses JVM Clojure type hinting, where we don't rely on reflection:

(set! *warn-on-reflection* true)

(def ^java.util.concurrent.ThreadPoolExecutor thread-pool
  (java.util.concurrent.Executors/newCachedThreadPool))
(def fut (.submit thread-pool ^Runnable (fn [] 3)))
@fut  ;; => nil

Now let's do the same with Callable:

(set! *warn-on-reflection* true)

(def ^java.util.concurrent.ThreadPoolExecutor thread-pool
  (java.util.concurrent.Executors/newCachedThreadPool))
(def fut (.submit thread-pool ^Callable (fn [] 3)))
@fut ;; => 3

So we see the issue: depending on the overload of .submit we get a different value when we dereference the future, either nil or the value returned from the function.

So far, babashka has relied exclusively on runtime reflection to implement Java interop. So we do get into a problem with the above snippet, unless we add type hints. But so far babashka, or more specifically, SCI hasn't made use of type hints to determine the most suitable method. The Clojure compiler does this, but as you know, SCI interprets code and doesn't make use of the clojure Compiler. It does use a forked version of clojure.lang.Reflector, clojure's runtime reflection code, aptly renamed to sci.impl.Reflector. So far, pretty much the only change to that code was making some methods public that were used internally by SCI. To fix the above problem, SCI now actually makes use of type hints and passes these to sci.impl.Reflector. So in the newly published version of babashka, this code:

(def thread-pool (java.util.concurrent.Executors/newCachedThreadPool))
(def fut (.submit thread-pool ^Callable (fn [] 3)))
@fut ;;=> 3

will consistently return 3 and when changing Callable to Runnable, you'll get nil. Note that the above snippet will still have the ambiguous behavior in JVM Clojure, since it doesn't have enough type hints to figure out the right method at compile time and clojure.lang.Reflector does nothing with type hints. Once the Clojure compiler finds out that you're calling .submit on a java.util.concurrent.ExecutorService though, the code will run with the expected method.

Can you think of more methods in the Java standard library which have this ambiguity when relying solely on Clojure reflection? I'd love to hear about those to see if they work reliably in babashka given some extra help through type hints.

Thanks to Tim Pote for thinking along when fixing the issues in babashka and reading a preview of this blog post.

Published: 2025-04-26

Tagged: clojure babashka

OSS updates January and February 2025

In this post I'll give updates about open source I worked on during January and February 2025.

To see previous OSS updates, go here.

Sponsors

I'd like to thank all the sponsors and contributors that make this work possible. Without you, the below projects would not be as mature or wouldn't exist or be maintained at all.

Current top tier sponsors:

Open the details section for more info about sponsoring.

Sponsor info

If you want to ensure that the projects I work on are sustainably maintained, you can sponsor this work in the following ways. Thank you!

On to the projects that I've been working on!

Updates

As I'm writing this I'm still recovering from a flu that has kept me bedridden for a good few days, but I'm starting to feel better now.

Here are updates about the projects/libraries I've worked on in the last two months.

  • clj-kondo: static analyzer and linter for Clojure code that sparks joy.

    • Unreleased:
    • #2493: reduce image size of native image
    • 2025.02.20:
    • #2473: New linter: :unknown-ns-options will warn on malformed (ns) calls. The linter is {:level :warning} by default. (@Noahtheduke)
    • #2475: add :do-template linter to check args & values counts (@imrekoszo)
    • #2465: fix :discouraged-var linter for fixed arities
    • #2277: prefer an array class symbol over (Class/forName ...) in defprotocol and extend-type
    • #2466: fix false positive with tagged literal in macroexpand hook
    • #2463: using :min-clj-kondo-version results in incorrect warning (@imrekoszo)
    • #2464: :min-clj-kondo-version warning/error should have a location in config.edn (@imrekoszo)
    • #2472 hooks api/resolve should return nil for unresolved symbols and locals
    • #2472: add api/env to determine if symbol is local
    • #2482: Upgrade to Oracle GraalVM 23
    • #2483: add api/quote-node and api/quote-node? to hooks API (@camsaul)
    • #2490: restore unofficial support for ignore hints via metadata
  • squint: CLJS syntax to JS compiler

    • Fix #609: make remove return a transducer when no collection is provided
    • Fix #611: Implement the set? function (@jonasseglare)
    • Fix #613: Optimize aset
    • Fix #626: Implement take-last
    • Fix #615: (zero? "0") should return false
    • Fix #617: deftype field name munging problem
    • Fix #618: Named multi-arity fn args don't get munged (@grayrest)
    • Fix #622: operator precendence issue with | and if
    • Add clojure.string functions lower-case, upper-case, capitalize (@plexus)
    • Fix #605: merge command line --paths with squint.edn config properly
    • Fix #607: make mapcat return a transducer if no collections are provided (@jonasseglare)
  • babashka: native, fast starting Clojure interpreter for scripting.

    • Experimenting upgrading to new beta core.async, work in is a branch ready to be merged
    • #1785: Allow subclasses of Throwable to have instance methods invoked (@bobisageek)
    • #1791: interop problem on Jsoup form element
    • #1793: Bump rewrite-clj to 1.1.49 (fixes parsing of foo// among other things)
    • Bump deps.clj
    • Bump fs
  • fs - File system utility library for Clojure

    • v0.5.24 (2025-01-09)
    • #135: additional fix for preserving protocol when calling fs/path on multiple arguments (@Sohalt)
  • SCI: Configurable Clojure/Script interpreter suitable for scripting

    • Records should have keys present and set to nil
  • deps.clj: A faithful port of the clojure CLI bash script to Clojure

    • Catch up with several new versions of clojure CLI
    • Fix #132: copy install tools.edn to config dir when install version is newer, similar to clojure CLI bash script
    • Adds support for XDG_DATA_HOME environment variable according to XDG Base Directory Specification
  • sql pods: babashka pods for SQL databases

  • edamame: Configurable EDN/Clojure parser with location metadata

    • Fix #115: add location to exception for invalid keyword
  • rewrite-edn: Utility lib on top of rewrite-clj with common operations to update EDN while preserving whitespace and comments

    • #40: assoc/update now handles map keys that have no indent at all (@lread)
    • #43: bump rewrite-clj to 1.1.49 (@lread)
    • #40: assoc/update now handles map keys that have no indent at all (@lread)
    • #40: assoc/update now aligns indent to comment if that's all that is in the map (@lread)
    • #40: update now indents new entries in same way as assoc (@lread)

Other projects

These are (some of the) other projects I'm involved with but little to no activity happened in the past month.

Click for more details - [CLI](https://github.com/babashka/cli): Turn Clojure functions into CLIs! - [scittle](https://github.com/babashka/scittle): Execute Clojure(Script) directly from browser script tags via SCI - [nbb](https://github.com/babashka/nbb): Scripting in Clojure on Node.js using SCI - [rewrite-clj](https://github.com/clj-commons/rewrite-clj): Rewrite Clojure code and edn - [pod-babashka-go-sqlite3](https://github.com/babashka/pod-babashka-go-sqlite3): A babashka pod for interacting with sqlite3 - [tools-deps-native](https://github.com/babashka/tools-deps-native) and [tools.bbuild](https://github.com/babashka/tools.bbuild): use tools.deps directly from babashka - [http-client](https://github.com/babashka/http-client): babashka's http-client
- [cherry](https://github.com/squint-cljs/cherry): Experimental ClojureScript to ES6 module compiler - [http-server](https://github.com/babashka/http-server): serve static assets - [bbin](https://github.com/babashka/bbin): Install any Babashka script or project with one comman - [sci.configs](https://github.com/babashka/sci.configs): A collection of ready to be used SCI configs. - Added a configuration for `cljs.spec.alpha` and related namespaces - [qualify-methods](https://github.com/borkdude/qualify-methods) - Initial release of experimental tool to rewrite instance calls to use fully qualified methods (Clojure 1.12 only0 - [clerk](https://github.com/nextjournal/clerk): Moldable Live Programming for Clojure - Add support for `:require-cljs` which allows you to use `.cljs` files for render functions - Add support for nREPL for developing render functions - [process](https://github.com/babashka/process): Clojure library for shelling out / spawning sub-processes - Work has started to support prepending output (in support for babashka parallel tasks). Stay tuned. - [neil](https://github.com/babashka/neil): A CLI to add common aliases and features to deps.edn-based projects.
- [quickdoc](https://github.com/borkdude/quickdoc): Quick and minimal API doc generation for Clojure - [tools](https://github.com/borkdude/tools): a set of [bbin](https://github.com/babashka/bbin/) installable scripts - [sci.nrepl](https://github.com/babashka/sci.nrepl): nREPL server for SCI projects that run in the browser - [html](https://github.com/borkdude/html): Html generation library inspired by squint's html tag - [instaparse-bb](https://github.com/babashka/instaparse-bb): Use instaparse from babashka - [babashka.json](https://github.com/babashka/json): babashka JSON library/adapter - [squint-macros](https://github.com/squint-cljs/squint-macros): a couple of macros that stand-in for [applied-science/js-interop](https://github.com/applied-science/js-interop) and [promesa](https://github.com/funcool/promesa) to make CLJS projects compatible with squint and/or cherry. - [grasp](https://github.com/borkdude/grasp): Grep Clojure code using clojure.spec regexes - [lein-clj-kondo](https://github.com/clj-kondo/lein-clj-kondo): a leiningen plugin for clj-kondo - [http-kit](https://github.com/http-kit/http-kit): Simple, high-performance event-driven HTTP client+server for Clojure. - [babashka.nrepl](https://github.com/babashka/babashka.nrepl): The nREPL server from babashka as a library, so it can be used from other SCI-based CLIs - [jet](https://github.com/borkdude/jet): CLI to transform between JSON, EDN, YAML and Transit using Clojure - [pod-babashka-fswatcher](https://github.com/babashka/pod-babashka-fswatcher): babashka filewatcher pod - [lein2deps](https://github.com/borkdude/lein2deps): leiningen to deps.edn converter - [cljs-showcase](https://github.com/borkdude/cljs-showcase): Showcase CLJS libs using SCI - [babashka.book](https://github.com/babashka/book): Babashka manual - [pod-babashka-buddy](https://github.com/babashka/pod-babashka-buddy): A pod around buddy core (Cryptographic Api for Clojure). - [gh-release-artifact](https://github.com/borkdude/gh-release-artifact): Upload artifacts to Github releases idempotently - [carve](https://github.com/borkdude/carve) - Remove unused Clojure vars - [4ever-clojure](https://github.com/oxalorg/4ever-clojure) - Pure CLJS version of 4clojure, meant to run forever! - [pod-babashka-lanterna](https://github.com/babashka/pod-babashka-lanterna): Interact with clojure-lanterna from babashka - [joyride](https://github.com/BetterThanTomorrow/joyride): VSCode CLJS scripting and REPL (via [SCI](https://github.com/babashka/sci)) - [clj2el](https://borkdude.github.io/clj2el/): transpile Clojure to elisp - [deflet](https://github.com/borkdude/deflet): make let-expressions REPL-friendly! - [deps.add-lib](https://github.com/borkdude/deps.add-lib): Clojure 1.12's add-lib feature for leiningen and/or other environments without a specific version of the clojure CLI

Published: 2025-02-28

Tagged: clojure oss updates

Archive