I see. very clever. I'm not used to loop constructs with no side effect. On Tue, Jun 2, 2009 at 12:21 PM, Konrad Hinsen <konrad.hin...@laposte.net> wrote: >> I saw that clojure has loop. But in other functional languages, >> using loops are always discouraged. So I didn't know if loop >> was the "clojure" idiomatic way of doing this. > > > Loops in Clojure are purely functional. They are in fact equivalent > to an embedded recursive function. Unlike the typical use of loops > in, say, Java, nothing is changed inside a loop, so there are no side > effects. > > Here's your example with the loop rewritten as an explicit recursive > function: > > (let [size 10 > loop-fn (fn [max] > (if (or (>= (/ max (Math/log max)) size) > (>= max Integer/MAX_VALUE) > (<= max 0)) > max > (recur (* 2 max))))] > (loop-fn 2)) > > As you can see, the differences are cosmetic. There is no need to > have a bad functional conscience for using loops! > > Konrad. > > > >
-- Omnem crede diem tibi diluxisse supremum. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---