I have a large text file that I want to process in Clojure.
I need to process it 2 lines at a time.
I decided to use a for loop so that I could pull 2 ββlines for each pass with the following binding (rdr is my reader):
[[line-a line-b] (partition 2 (line-seq rdr))]
(I would be interested to know other ways to get 2 rows for each iteration of the loop, but that is not the question of my question).
When I try to get the loop to work (using a simpler binding for these tests), I see the following behavior, which I cannot explain:
Why
(with-open [rdr (reader "path/to/file")] (for [line (line-seq rdr)] line))
triggers a thread exception with closure
while
(with-open [rdr (reader "path/to/file")] (doseq [line (line-seq rdr)] (println line)))
work?
source share