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

I find it really useful when (for example) reading from a non-blocking
socket. Here is a quick (silly) example:

(let-while [x (if (> (rand) 0.2) "Yep!" nil)]
        (println x)
        (println (str x)))

The idea is that x is bound to the if expression and if x is true the
println's are executed. Repeat until x is false/nil.

Thanks
Morten

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