I'm about to pull out my hair on this one.
For some context, I'm implementing a simple algorithm in Clojure. assume the following data structures
(def inf Double/POSITIVE_INFINITY)
(def min-dist (atom {:1 {:1 0 :2 4} :2 {:1 4 :2 0 :3 5} :3 {:2 5 :3 0}}))
(def vertexes [:1 :2 :3])
The following code will crash after the first iteration:
(for [k vertexes i vertexes j vertexes]
((println (str " " i " " k " "j))
(if (> (get-in @min-dist [i j] inf) (+ (get-in @min-dist [i k] inf) (get-in @min-dist [k j] inf)) )
(do
;;do some stuff
(println "bla"))
)))
With the following output:
:1 :1 :1 NullPointerException
user.core/eval7683/iter--7675--7684/fn--7685/iter--7677--7686/fn--7687/iter--7679--7688/fn--7689/fn--7690 (form-init1244434853692676604.clj:2)
I do understand that I'm probably violating some references during the if here. But I'm new to clojure and have no idea on what I'm doing wrong here. Something to do with the triple-for over the same seq?