How to read lines from stdin (*in*) in clojure

后端 未结 4 1977
情歌与酒
情歌与酒 2020-12-13 13:09

I am writing my first clojure program, and want to read lines from stdin.

When I try this:

(doall (map #(println %) (line-seq *in*)))
4条回答
  •  心在旅途
    2020-12-13 13:29

    You should probably use doseq instead of doall:

    (doseq [line (line-seq (java.io.BufferedReader. *in*))] 
        (println line))
    

    doall:

    Walks through the successive nexts of the seq, retains the head and returns it, thus causing the entire seq to reside in memory at one time.

    doseq:

    Does not retain the head of the sequence. Returns nil.

提交回复
热议问题