> What would be the best (idiomatic and efficiant) solution then?
> - wrap my file under a lazy sequence, call take & drop recursively
> with recur
> - just call readLine method directly when I need more lines and
> process them.
>
Hi,
Have a look at the functions:
line-seq
and
clojure.java.io/r
Hi,
I'am not really sure on your explanation here.
For me if the processor, JVM or clojure compiler cannot prove it
doesn't change the semantics, the optimization will not be applyed.
readLine behing a java method call, it can perform any operations and
thus clojure compiler will not change the e
The problem with the direct call of the readLine() method is that it might
not work some day like it appears to work today. Specifically, the meaning
of your program depends on:
- evaluation order the compiler chooses
- the fact that the compiler obviously does not do common subexpression
I have done futher experimentations and have found that, if I call
directly readLine method, it work like a normal stream:
(let [reader (java.io.BufferedReader. (java.io.FileReader.
"liars.txt"))]
[(.readLine reader) (.readLine reader) (.readLine reader) (.readLine
reader)])
=> ["5" "Stephen 1
The problem you're having doesn't have anything to do with file
reads. Every time you call (take 5 data), you're calling it on the
same item 'data'; your variable 'data' doesn't change between each
call. The chief thing you have to understand about Clojure is that
variables never change. Never.