Loading Data From a csv


#1

Hey Eric,

I am going through your course Complete Web App from Scratch and I seem to have hit a wall - how do you go about debugging this function:

(defn read-and-insert [upload-id rdr]
  (let [[header & rows] (csv/read-csv rdr)]
    (doseq [row rows]
      (let [row-id (create-row upload-id)]
        (doseq [[key value] (map vector header row)]
          (create-cell row-id key value))))))

The broad question that I am generally curious about are good techniques used to debug in Clojure, but more specifically, how you would go about debugging the above in a clean way?

For example, lets say I want to see what each row looks like in [row rows] - how could I do that? I placed a print statement in there, but this did not seem to work, which, as far as I know, is because the above block of code is a lazy sequence.

Any input would be great!


#2

Hey @tkjone,

To print out each row, I’d just add a print to the body of the doseq:

(doseq [row rows]
  (prn row)
  ...

doseq is not lazy, so it should work just fine.

Rock on!
Eric