I am trying to add a section to a Clojure code. After line no. 99 of the below code:
https://github.com/lspector/Clojush/blob/master/src/clojush/pushgp/breed.clj
I want to add these codes:
(if (= num-parents 2)
(let [initial-other-parents (vec (repeatedly
(+ num-parents 4) ; selecting parents more than required by 4
(fn []
(loop [re-selections 0
other (select population argmap)]
(if (and (= other first-parent)
(< re-selections
(:self-mate-avoidance-limit argmap)))
(recur (inc re-selections)
(select population argmap))
other)))))
all-parents (concat (if (nil? first-parent) ;gathering all created parents
nil
(vector first-parent))
initial-other-parents)
(defn eclid-dist [u v] ;defining a function to calculate distances
(->> (mapv - u v)
(mapv #(Math/pow % 2))
(reduce +)
Math/sqrt))
(defn find-largest-dist-pair [vec-map] ;defining a function to return two vectors (parents) with the largest distance
(apply max-key second
(for [[[k0 v0] & r] (iterate rest vec-map)
:while r
[k1 v1] r]
[[k0 k1] (eclid-dist v0 v1)])))
final-parents (find-largest-dist-pair (:error all-parents)) ;selecting two parents with the largest distance
op-fn (:fn (get genetic-operators operator)) ; extracting the operator
child (apply op-fn (concat final-parents ; creating child
(vector (assoc argmap
:population population))))]
)
For running the added part line by line, I extracted values before the changes using adding the below code after line 84 of the main code:
(spit "initial-setting.edn" {:operator-list operator-list
:first-parent first-parent
:population population
:location location
:rand-gen rand-gen
:argmap argmap})
My question is:
- what is the best way to assign extracted values by "spit" to variables and execute the added section line by line for debugging? I am using Calva as IDE and tried to put #break and use lein to run the code and debug it but it did not work. Here is my pervious post on that: How to set a breakpoint in a Clojure program using Calva?