 ; :mode=clojure:
+
+;(.printStackTrace *e)
+;for i in /tmp/*.dot ; do echo $i && dot -Tsvg $i -o $i.svg; done
 
 (defrecord monoid [measure-fn combine-fn])
 (defrecord node-2 [v a b])

    (finger-tree-single. monoid e))
(defn make-finger-tree-deep [monoid l m r]
    (if (delay? m)
        (finger-tree-deep.
            monoid
            (delay (apply
                (:combine-fn monoid)
                (map
                    (fn [e] (extract-measure e monoid))
                    (concat
                        l
                        ((fn [v] (if (nil? v) [] [v])) (force m))
                        r))))
            l m r)
        (throw (IllegalArgumentException. "middle tree is not a delay"))))

; Reverse cons
(defn snoc [a lst] (concat lst [a]))
; Reverse rest
(defn tser [lst] (take (dec (count lst)) lst))

; Adds a new element to the front of the finger tree
(defmulti push-front (fn [tree value] (class tree)))

        1 [(make-node-3 monoid a b (first r))]
        2 [(make-node-2 monoid a b) (apply make-node-2 monoid r)]
        (cons (make-node-3 monoid a b (first r)) (apply nodes monoid (rest r)))))

(defn force-early [d] (do (force d) d))

(defmulti app3 (fn [l m r] [(class l) (class r)]))
(defmethod app3 [finger-tree-empty ::any] [l m r]
