So I have the following function which works well when called from the REPL:
(defn plot-data-files
"Produces a file with x-axis values on 1st column and y-axis values on the
2nd column"
[]
(let [filename (user-input "file to which you want to write plot output")
x-values file-data-days
y-values (get-dndtf)
file-writer (new java.io.FileWriter filename)]
(if (= (first y-values) za-not-found)
(println za-not-found)
(for [index (range (count x-values))]
(binding [*out* file-writer]
(prn (Double/parseDouble (str (nth x-values index)))
(Double/parseDouble (str (nth y-values index)))))))))
However, when I try using Leinigen to produce a jar file, the function no longer writes to files. So I tried calling -main from the REPL, and sure enough, the function also does not write to files, even though it does when called by itself. So, I tried defining another function:
(defn call-plot-function
"Basically calls the plot function, plot-data-files"
[] (plot-data-files))
and sure enough, it works. I try calling -main again, but this time calling call-plot-function instead of plot-data-files directly:
(defn -main [& args]
(get-all-file-data)
(while (not (= \n (first (user-input "whether you want to output more plot
files"))))
(call-plot-function)))
And again, plot-data-files magically does not write file output when -main is called. What should I be doing here?
foris not a loop. Your-mainis returning a lazy sequence, and you never force any of its elements. The repl forces in order to print, which is why you see the difference. If you want side effects instead of a sequence,doseqhas otherwise the same semantics asfor.