Does "Concat" violate the laziness of "line-seq"?

The following code appears, which causes line-seq to read 4 lines from file . Is this some kind of buffering mechanism? Do I need to use lazy-cat ? If so, how can I apply to create a macro in a sequence, as if it were variable arguments?

 (defn char-seq [rdr] (let [coll (line-seq rdr)] (apply concat (map (fn [x] (println \,) x) coll)))) (def tmp (char-seq (clojure.contrib.io/reader file))) ;, ;, ;, ;, #'user/tmp 
+1
source share
1 answer

Part of what you see is related to apply , because you need to implement so many arguments to define a function. For example:.

  user => (defn foo [& args] nil)
 # 'user / foo
 user => (def bar (apply foo (iterate # (let [i (inc%)] (println i) i) 0))))
 one
 # 'user / bar
 user => (defn foo [x & args] nil)
 # 'user / foo
 user => (def bar (apply foo (iterate # (let [i (inc%)] (println i) i) 0))))
 one
 2
 # 'user / bar
 user => (defn foo [xy & args] nil)
 # 'user / foo
 user => (def bar (apply foo (iterate # (let [i (inc%)] (println i) i) 0))))
 one
 2
 3
 # 'user / bar
+3
source

All Articles