Thanks Steve and Cosmin! I understand it now.

On Tue, Jan 20, 2009 at 4:53 PM, Stephen C. Gilardi <squee...@mac.com> wrote:
>
> 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
>
>



-- 
R. Mark Volkmann
Object Computing, Inc.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to