Skip to content

Instantly share code, notes, and snippets.

@Netpilgrim
Created September 3, 2011 12:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Netpilgrim/1191098 to your computer and use it in GitHub Desktop.
Save Netpilgrim/1191098 to your computer and use it in GitHub Desktop.
Problem with -> (solved)
(defprotocol Graph
(set-vertex [this v])
(set-edge [this from to]
[this from to weight]))
(defrecord DirectedGraph [vs em wm]
;; A directed graph: vs is a sorted set of vertices, em is a map from vertices
;; to a sorted set of adjacent vertices, wm is a map from edges given as
;; vertex tuple [from to] to weights.
Graph
(set-vertex [_ v]
(DirectedGraph. (conj vs v)
(conj em [v (sorted-set)])
wm))
(set-edge [this from to]
(set-edge this from to nil))
(set-edge [_ from to weight]
(DirectedGraph. vs
(conj (em from) to)
(conj wm [[from to] weight]))))
(def test-graph (-> (DirectedGraph. (sorted-set) {} {})
(set-vertex :q)
(set-vertex :a)
(set-vertex :b)
(set-vertex :c)
(set-vertex :d)
(set-vertex :s)
(set-edge :q :a 8)
(set-edge :q :c 3)
(set-edge :a :b 2) ; This is line 33.
(set-edge :a :c 2)
(set-edge :a :d 1)
(set-edge :b :c 2)
(set-edge :b :s 1)
(set-edge :c :d 8)
(set-edge :d :s 7)))
;; Compiler error message:
;; error: java.lang.ClassCastException: clojure.lang.PersistentList cannot be cast to clojure.lang.IFn (graph.clj:33)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment