Rewrite of hsps.py in Clojure.