With clojure read/read-string function, how do i r

2019-07-04 11:33发布

As titled, If I do

(read-string (slurp "somefile"))

This will only give me the first object in the file, meaning if "somefile" is as below:

(a obj) (b obj)

Then I only get (a obj) as the result.

How do i get a list of all objects, like this?

((a obj) (b obj))

Thanks.

2条回答
萌系小妹纸
2楼-- · 2019-07-04 11:46

I usually wrap stuff in a list,

(read-string (str \( (slurp "somefile")  \)))
查看更多
一纸荒年 Trace。
3楼-- · 2019-07-04 12:09
(defn read-all
  [input]
  (let [eof (Object.)]
    (take-while #(not= % eof) (repeatedly #(read input false eof)))))
查看更多
登录 后发表回答