Skip to content →

Efficiency of Clojure’s built-in set operations

If you’re using Clojure’s built-in set operations, clojure.set/union/intersection/difference, you should be aware that their speed currently depends (sometimes dramatically) on the order of the arguments given. And, since clojure.set/difference is not commutative, it is simply needlessly slow if the second…

Computing java.util.List hashCode()s back-to-front

For some applications, it could be desirable to compute java.util.List hashCode()s backwards, recursively from back to front, rather than front-to-back as defined in the API [1]. For instance, in Clojure this would enable computing the hash values for all of…

Strongly Connected Components in (mostly?) idiomatic Clojure

A friend asked how to find strongly connected components in a graph in idiomatic Clojure. This is what I came up with: (defn edge-list [g] (mapcat (fn [[k v]] (map (partial vector k) v)) g))   (defn reverse-graph [g] (reduce…

Matching in Clojure

I was trying to write a PDDL parser in Clojure, and realized it could be handy to have something that does the opposite of `(~x ~@y). In other words, it takes a two versions of a syntax-tree, one with variables…

Getting used heap space in Allegro CL (and other Lisps)

If you’re running experiments in Lisp and want to know the total amount of memory currently in use (i.e., by live objects), it’s much less straightforward than you might think. The following code gets this number in a handful of…