Hi, On Aug 3, 8: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?
The :while modifier works on the clause just before it. That means that in your case the :while works on the `y` clause, but there `x` is constant. So you get a result when `x` is equal to two. When you put the :while at the `x` clause you get the expected empty seq. user=> (for [x (range 1 10) :while (= x 2) y (range 1 10)] [x y]) () Hope this helps. Sincerely Meikel --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---