Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (require '[clojure.java.io :as io])
- ;; Will reproduce stack overflow if this file has >= 10000 lines.
- (def input-file "/home/xgp/tmp/def")
- (defn make-reader [input]
- (if (string? input)
- (io/reader input)
- (first input)))
- (defn read-line-or-nil [input]
- (let [reader (make-reader input)]
- (if-let [lines (seq (line-seq reader))]
- [reader lines]
- (do (. reader close)
- nil))))
- (defn read-inputs [inputs]
- (keep read-line-or-nil inputs))
- (let [inputs (atom [input-file])]
- (loop []
- (swap! inputs read-inputs)
- (when-let [sq (seq @inputs)]
- (let [[[_ [line]]] sq]
- (println line)
- (recur)))))
Advertisement
Add Comment
Please, Sign In to add comment