Skip to content
Create a gist now

Instantly share code, notes, and snippets.

Embed URL


Subversion checkout URL

You can clone with
Download ZIP
simple example of visualizing prismatic graphs with graphviz
(require '[plumbing.core :refer [fnk]])
(require '[plumbing.graph :as graph])
(defn calculate-deps [f]
(map (fn [parent] [parent (first f)]) (-> f second meta first second first keys)))
(defn print-dot [graph]
(println (clojure.string/join "\n"
(map (fn [r] (str "\""(first r) "\" -> \"" (second r) "\";"))
(mapcat (fn [k] (calculate-deps k)) (graph/->graph graph))))))
;; Example graph
(def stats-graph
"A graph specifying the same computation as 'stats'"
{:n (fnk [xs] (count xs))
:m (fnk [xs n] (/ (+ identity xs) n))
:m2 (fnk [xs n] (/ (+ #(* % %) xs) n))
:v (fnk [m m2] (- m2 (* m m)))})
(print-dot stats-graph)
; Outputs this:
; digraph "example" {
; ":xs" -> ":n";
; ":xs" -> ":m";
; ":n" -> ":m";
; ":xs" -> ":m2";
; ":n" -> ":m2";
; ":m2" -> ":v";
; ":m" -> ":v";
; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.