Clojure
Clojure Deref (June 23, 2023)

Clojure Deref (June 23, 2023)

23 June 2023
Alex Miller

Welcome to the Clojure Deref! This is a weekly link/news roundup for the Clojure ecosystem. (@ClojureDeref RSS)

From the core

This week, I continued to make steady progress on integration support for Java functional interfaces. The gist of this is when you call a Java method that takes a functional interface, you should be able to pass a Clojure IFn without making an explicit adapter from IFn to the target interface. So calling (.filter stream even?) should "just work", without needing to reify a java.util.function.Predicate to call your IFn.

We’ve looked at a lot of approaches for this, but the path we are pretty far down at this point is to detect when this mismatch ocurs and invoke an adapter for you. We are mimicking what the Java compiler does to create this as if it were a lambda expression in Java - this avoids creating more classes at compile time and is fully inlineable at runtime. There are a lot of corner cases around primitives, avoiding the creation of the adapter when one isn’t needed, etc, but that is getting close.

Fogus has been working on kind of the opposite problem - being able to refer to a Java method in Clojure code and have it work like an IFn, so you could (for example), map a static method directly over a Clojure collection without creating an anonymous function. The concerns are different than the prior case and I think we will probably end up handling this in the compiler with a generated reified class that implements IFn. There are interesting tensions between syntax, allowed capabilities (multiple arities, type overloading, primitive support, varargs, etc), and the implementation approach, so we’ve kind of bounced around the design space several times here.

Additionally, I think we’ve pretty much finalized a set of new stream helper functions to allow Java streams to be used more directly in Clojure.

All of these features are on track for 1.12, plus maybe a couple more (in particular I want to look at better varargs support in combination with the features above). Combining all of these will really make interop with newer Java libs that make use of functions and streams much much better.

Blogs, articles, and projects

Libraries and Tools

New releases and tools this week:

  • aws-api 0.8.681 - AWS, data driven

  • antq 2.5.1095 - Point out your outdated dependencies

  • bosquet 0.3.0 - LLMOps tools

  • openai-clojure 0.8.0 - Clojure functions to drive the OpenAI API

  • babashka.el 1.0.3 - Babashka Tasks for Emacs

  • vocabulary 0.4.0 - Utilities to map between clojure namespaced keywords and RDF-style URIs

  • license-finder 0.2.0 - Finds licenses of your Clojure(Script) dependencies

  • deps-try 0.7.0 - Try out Clojure libraries via rebel-readline

  • hiccup 0.0.25 - Enlive-backed Hiccup implementation (clj-only)

  • calva 2.0.371 - Clojure & ClojureScript Interactive Programming for VS Code

  • clj-otel 0.2.3 - Clojure API for adding telemetry to your libraries and applications using OpenTelemetry

  • bbin 0.2.0-beta1 - Install any Babashka script or project with one command

  • cli 0.7.52 - Turn Clojure functions into CLIs

  • pretty 1.4.4 - Library for helping print things prettily

  • auspex 1.0.0 - Mini wrapper over java CompletableFuture with a manifold deferred after-taste