开发者

With clojure read/read-string function, how do i read in a .clj file to a list of objects

开发者 https://www.devze.com 2023-03-22 23:12 出处:网络
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:

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:

开发者_如何学Python(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.


(defn read-all
  [input]
  (let [eof (Object.)]
    (take-while #(not= % eof) (repeatedly #(read input false eof)))))


I usually wrap stuff in a list,

(read-string (str \( (slurp "somefile")  \)))
0

精彩评论

暂无评论...
验证码 换一张
取 消