Re: Lazy behavior

2011-11-02 Thread David Powell
> 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

Re: Lazy behavior

2011-11-02 Thread Nicolas
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

Re: Lazy behavior

2011-11-01 Thread Ingo
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

Re: Lazy behavior

2011-11-01 Thread Nicolas
 "Read a text file, line per line, lazily returning nil when end of > > file has been reached. Each line is a vector of words" > >    (let [reader (java.io.BufferedReader. (java.io.FileReader. file- > > name))] > >      (map split-words (repeatedly #(.readLine re

Re: Lazy behavior

2011-10-31 Thread nchurch
o.BufferedReader. (java.io.FileReader. file- > name))] >      (map split-words (repeatedly #(.readLine reader) > > (defn next-line [lines] >   (first (take 1 lines))) > > So basically, a file is a lazy sequence of lines, and each line is a > vector of words. > > Lazy be

Lazy behavior

2011-10-31 Thread Nicolas
ader (java.io.BufferedReader. (java.io.FileReader. file- name))] (map split-words (repeatedly #(.readLine reader) (defn next-line [lines] (first (take 1 lines))) So basically, a file is a lazy sequence of lines, and each line is a vector of words. Lazy behavior seems to be wor