 ; Define train and test cases
 (def replace-space-train-and-test-cases
   (get-replace-space-train-and-test replace-space-data-domains))
+
+(defn replace-space-error-function
+  ([program]
+   (replace-space-error-function program :train))
+  ([program data-cases] ;; data-cases should be :train or :test
+   (replace-space-error-function program data-cases false))
+  ([program data-cases print-outputs]
+   (let [behavior (atom '())
+         errors (flatten
+                 (doall
+                  (for [[input [correct-output correct-int]] (case data-cases
+                                                               :train (first replace-space-train-and-test-cases)
+                                                               :test (second replace-space-train-and-test-cases)
+                                                               [])]
+                    (let [final-state (run-push program
+                                                (->> (make-push-state)
+                                                     (push-item input :input)
+                                                     (push-item "" :output)))
+                          printed-result (stack-ref :output 0 final-state)
+                          int-result (stack-ref :integer 0 final-state)]
+                      (when print-outputs
+                        (println (format "\n| Correct output: %s\n| Program output: %s" (pr-str correct-output) (pr-str printed-result)))
+                        (println (format "| Correct integer: %2d | Program integer: %s" correct-int (str int-result))))
+                                        ; Record the behavior
+                      (when @global-print-behavioral-diversity
+                        (swap! behavior conj [printed-result int-result]))
+                                        ; Error is Levenshtein distance for printed string and
+                                        ; integer distance for returned integer
+                      (vector
+                       (levenshtein-distance correct-output printed-result)
+                       (if (number? int-result)
+                         (abs (- int-result correct-int)) ;distance from correct integer
+                         1000)        ;penalty for no return value
+                       )))))]
+     (when @global-print-behavioral-diversity
+       (swap! population-behaviors conj @behavior))
+     errors)))
 
 (defn replace-space-with-newline-initial-report
   [argmap]

                  (count (filter #(not= \space %) in))]))
       inputs))

(defn make-replace-space-with-newline-error-function-from-cases
  [train-cases test-cases]
  (fn the-actual-replace-space-error-function
    ([program]
      (the-actual-replace-space-error-function program :train))
    ([program data-cases] ;; data-cases should be :train or :test
                          (the-actual-replace-space-error-function program data-cases false))
    ([program data-cases print-outputs]
      (let [behavior (atom '())
            errors (flatten
                     (doall
                       (for [[input [correct-output correct-int]] (case data-cases
                                                                    :train train-cases
                                                                    :test test-cases
                                                                    [])]
                         (let [final-state (run-push program
                                                     (->> (make-push-state)
                                                       (push-item input :input)
                                                       (push-item "" :output)))
                               printed-result (stack-ref :output 0 final-state)
                               int-result (stack-ref :integer 0 final-state)]
                           (when print-outputs
                             (println (format "\n| Correct output: %s\n| Program output: %s" (pr-str correct-output) (pr-str printed-result)))
                             (println (format "| Correct integer: %2d | Program integer: %s" correct-int (str int-result))))
                           ; Record the behavior
                           (when @global-print-behavioral-diversity
                             (swap! behavior conj [printed-result int-result]))
                           ; Error is Levenshtein distance for printed string and
                           ; integer distance for returned integer
                           (vector
                             (levenshtein-distance correct-output printed-result)
                             (if (number? int-result)
                               (abs (- int-result correct-int)) ;distance from correct integer
                               1000) ;penalty for no return value
                             )))))]
        (when @global-print-behavioral-diversity
          (swap! population-behaviors conj @behavior))
        errors))))

(defn get-replace-space-train-and-test
  "Returns the train and test cases."
  [data-domains]


; Define the argmap
(def argmap
  {:error-function replace-space-error-function
   :atom-generators replace-space-atom-generators
   :max-points 3200
   :max-genome-size-in-initial-program 400
