3

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.

andy
  • 71
  • 1
  • 3

2 Answers2

10
(defn read-all
  [input]
  (let [eof (Object.)]
    (take-while #(not= % eof) (repeatedly #(read input false eof)))))
kotarak
  • 17,099
  • 2
  • 49
  • 39
5

I usually wrap stuff in a list,

(read-string (str \( (slurp "somefile")  \)))
Hamza Yerlikaya
  • 49,047
  • 44
  • 147
  • 241
  • 3
    Ya, i end up doing this as well, be aware to add a \n before \), if the last line is a comment, this will get you out of it. – andy Jul 27 '11 at 07:58