      (update-in [n1 :next] conj n2)
      (update-in [n2 :prev] conj n1)))
 
-(defn contains-node? [g n] (g n))
-(defn contains-edge? [g n1 n2] (get-in g [n1 :next n2]))
 (defn next-nodes [g n] (get-in g [n :next]))
 (defn prev-nodes [g n] (get-in g [n :prev]))
 (defn nodes [g] (keys g))
 
-(defn split-lines [str]
-  (filter (comp not empty?) (str/split str #"\n")))
+(defn split-lines [str] (filter (comp not empty?) (str/split str #"\n")))
 
 (defn nodify
   [line]
-  (let [stars (count (take-while #(= \* %) line))
-        label (clojure.string/trim (subs line stars))]
-    (if (> stars 0) (make-node stars label))))
+  (let [stars (count (take-while #(= \* %) line))]
+    (if (> stars 0) (make-node stars (clojure.string/trim (subs line stars))))))
 
 (defn insert-root [nodes] (conj nodes (make-node 0 "Utility")))
 

          {}
          (partition 2 1 nodeseq)))

(defn prolog
  [g]
  (println "digraph {
     rankdir=LR;
     node[shape=\"plaintext\"];
     edge[arrowhead=\"none\"];"))

(defn rank
  [nodes]
  (println "subgraph {\nrank=same;")
  (doseq [n nodes]
    (println (str (:id n) " [label=\"" (:label n) "\"];")))
  (println "}"))

(defn dependencies
  [g]
  (doseq [n (nodes g)
        trg (next-nodes g n)]
    (println (str (:id n) "->" (:id trg) ";"))))

(defn epilog
  [g]
  (println "}"))

(defn ranks-in [g] (set (map :level (nodes g))))

(defn emit-dot
  [g]
  (prolog g)
  (doseq [r (ranks-in g)]
    (rank (filter #(= r (:level %)) (nodes g))))
  (dependencies g)
  (epilog g))

(defn -main [& args]
  (doseq [f args]

  (:require (clojure [string :as str]))
  (:gen-class))

(let [id-sequence (atom 0)]
  (defn make-node [t l] {:id (str "node" (dosync (swap! id-sequence inc))) :level t :label l}))

(defn add-node [g n] (if (g n) g (assoc g n {:next #{} :prev #{}})))

