On Mon, Aug 3, 2009 at 2:47 AM, Jonas<jonas.enl...@gmail.com> wrote:
>
> I find the :while modifier non intuitive
>
> user=> (for [x (range 1 10) y (range 1 10) :while (= y 2)] [x y])
> ()
> user=> (for [x (range 1 10) y (range 1 10) :while (= x 2)] [x y])
> ([2 1] [2 2] [2 3] [2 4] [2 5] [2 6] [2 7] [2 8] [2 9])
>
> My (false) intuition told me that both expressions would have been
> evaluated to an empty sequence. Could someone explain the rationale
> behind the :while modifier?

:while only bails from the loop on which it is placed.  In
your examples that's the 'y' loop, so the 'x' loop is
unaffected by your :while and proceeds through its entire
range in both examples.  In the first example, the 'y'
loop never produces anything so the result is empty.

The :while modifier for 'doseq' behaves the same way.

This has come up before:
http://clojure-log.n01se.net/date/2009-06-12.html#15:02a-15:33

--Chouser

--~--~---------~--~----~------------~-------~--~----~
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
Note that posts from new members are moderated - please be patient with your 
first post.
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