That was it, thanks! On Feb 8, 5:01 pm, Alex Osborne <a...@meshy.org> wrote: > John Svazic <jsva...@gmail.com> writes: > > Snipping to the relevant portion of the exception (always look at the > last "Caused by"): > > > Caused by: java.lang.ClassCastException: clojure.lang.Cons cannot be > > cast to clojure.lang.Associative > > at clojure.lang.RT.assoc(RT.java:664) > > at net.auxesia.chromosome$mutate.invoke(chromosome.clj:58) > > So what that means is that a call to the "assoc" function on line 58 of > chromosome.clj is being passed a "Cons" object (a list cell) instead of > an "Associative" object (a vector or map). > > The assoc call in question is this: > > (let [old (:gene c) > idx (rand-int (count old)) > new (assoc old idx (char (mod (+ (int (nth old idx)) > (+ 32 (rand-int 90))) 122)))] > > So "old" must be a list when you're expecting a vector. Looking around > at places you assign (:gene c) we come to the "mate" function, > specifically: > > (let [... > child1 (into (drop pivot gene2) (reverse (take pivot gene1))) > child2 (into (drop pivot gene1) (reverse (take pivot gene2)))] > ... > (hash-map :gene child1 :fitness (fitness child1)) > ...) > > 'drop is lazy so returns a seq, calling 'into on a seq produces a list. > So try calling vec on each child to convert it into a vector.
-- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en