I'll take a crack at this.  It may appear that the doall and dorun return
something
different with subsequent calls but they don't actually.   The doall always
returns
the sequence (1 2) and dorun always returns nil.

The first time (doall x) is called the for loop executes and prints 1 2 (a
side effect
and is not returned from the for loop) and then returns the seq.  The second
time
it's called x is already assigned the seq and just returns it. It does not
execute
the for loop again.

The dorun call is similar, but instead of returning the seq of the for loop,
it always
returns nil.  According to the api docs, dorun is used to force side
effects.

On Mon, Dec 15, 2008 at 9:19 PM, wubbie <sunj...@gmail.com> wrote:

>
> Hello,
>
> doall and dorun returns different results from seond run on...
> e.g.
> user=> (def x (for [i (range 1 3)] (do (println i) i)))
> #'user/x
> user=> (doall x)
> 1
> 2
> (1 2)
> user=> (doall x)
> (1 2)
> user=> (doall x)
> (1 2)
> user=>
>
> user=> (def x (for [i (range 1 3)] (do (println i) i)))
> #'user/x
> user=> (dorun x)
> 1
> 2
> nil
> user=> (dorun x)
> nil
> user=> (dorun x)
> nil
> user=>
>
>
> What's the explanation for that?
>
> thanks
> sun
>
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
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