letronje (1) [Avatar] Offline
#1
I took https://github.com/joyofclojure/book-source/raw/master/src/joy/a.clj and added a

(println (astar [0 0] 900 world)) at the end

Instead of printing the expected result, here's the stack trace i get( I'm running clojure 1.2) .

Exception in thread "main" java.lang.ClassCastException: clojure.lang.LazySeq cannot be cast to java.lang.Comparable (astar.clj:0)
at clojure.lang.Compiler.eval(Compiler.java:5440)
at clojure.lang.Compiler.load(Compiler.java:5857)
at clojure.lang.Compiler.loadFile(Compiler.java:5820)
at clojure.main$load_script.invoke(main.clj:221)
at clojure.main$script_opt.invoke(main.clj:273)
at clojure.main$main.doInvoke(main.clj:354)
at clojure.lang.RestFn.invoke(RestFn.java:437)
at clojure.lang.Var.invoke(Var.java:373)
at clojure.lang.AFn.applyToHelper(AFn.java:169)
at clojure.lang.Var.applyTo(Var.java:482)
at clojure.main.main(main.java:37)
Caused by: java.lang.ClassCastException: clojure.lang.LazySeq cannot be cast to java.lang.Comparable
at clojure.lang.Util.compare(Util.java:6smilie
at clojure.lang.APersistentVector.compareTo(APersistentVector.java:402)
at clojure.lang.Util.compare(Util.java:6smilie
at clojure.lang.RT$DefaultComparator.compare(RT.java:257)
at clojure.lang.PersistentTreeMap.doCompare(PersistentTreeMap.java:302)
at clojure.lang.PersistentTreeMap.entryAt(PersistentTreeMap.java:289)
at clojure.lang.PersistentTreeMap.containsKey(PersistentTreeMap.java:94)
at clojure.lang.APersistentSet.contains(APersistentSet.java:33)
at clojure.lang.PersistentTreeSet.cons(PersistentTreeSet.java:52)
at clojure.lang.PersistentTreeSet.cons(PersistentTreeSet.java:17)
at clojure.lang.RT.conj(RT.java:524)
at clojure.core$conj.invoke(core.clj:7smilie
at clojure.lang.ArrayChunk.reduce(ArrayChunk.java:60)
at clojure.core$r.invoke(core.clj:797)
at clojure.core$into.invoke(core.clj:2615)
at joy.a$astar.invoke(astar.clj:62)
at joy.a$eval32.invoke(astar.clj:69)
at clojure.lang.Compiler.eval(Compiler.java:5424)
... 10 more
globulon (18) [Avatar] Offline
#2
Re: Chapter 7 , astar throws LazySeq cannot be cast to java.lang.Comparable
Change your neighbors function (the provided one in listing 5.1) with

(defn neighbors
  ([within-limit at] (neighbors [[-1 0] [1 0] [0 -1] [0 1]] within-limit at))
  ([deltas within-limit at]
  (filter
  (fn[neighbour]
  (every? #(< -1 % within-limit) neighbour))
  (map #(vec (map + at %)) deltas))))

now your return neighbors for [0 0] will be ([1 0] [0 1]) and not ((1 0) (0 1))