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…
Category archive for: Programming
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…
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…
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…
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…