On Fri, Oct 16, 2009 at 7:58 PM, mbrodersen <morten.broder...@gmail.com>wrote:
> > Hi, > > I am new to Clojure and I am wondering if there is anything similar to > the following macro already built in: > > (defmacro let-while > "Makes it easy to continue processing an expression as long as it is > true" > [[name expr] & forms] > `(loop [] > (let [~name ~expr] > (when ~name > ~...@forms > (recur))))) > Nice. But name is multiply evaluated. This might be preferable: (defmacro let-while "Makes it easy to continue processing an expression as long as it is true" [[name expr] & forms] (let [n# ~name] `(loop [] (let [~n# ~expr] (when ~n# ~...@forms (recur))))) This evaluates the name argument first, and only once, and (as required) evaluates expr and forms once each time around the loop, plus expr one additional time (the first time it evaluates to false). --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---