On Jan 20, 2009, at 5:32 PM, Mark Volkmann wrote:
Here's one: (defn read-my-file [] (with-open [reader (BufferedReader. (FileReader. "my-file.txt"))] (doall (line-seq reader)))) "line-seq" returns a lazy sequence, but you have to consume that sequence before "with-open" closes the file.How is it different if you change "doall" to "dorun"? According to their doc strings, they both "can be used to force any effects. Walks through the successive rests of the seq"
Using doall will cause read-my-file to return a seq of all the lines. dorun will return nil.
Here's a simpler example: user=> (doall (map #(do (prn %) %) [1 2 3])) 1 2 3 (1 2 3) user=> (dorun (map #(do (prn %) %) [1 2 3])) 1 2 3 nil user=> (Note the difference in return value.) --Steve
smime.p7s
Description: S/MIME cryptographic signature