I've found the following macro very useful: (similar to a standard
language while loop)

(defmacro while[v cnd & body]
   `(loop[]
      (let [~v ~cnd]
         (when ~v
            [EMAIL PROTECTED] (recur) ))))

Basically it repeatedly executes BODY while CND (which is constantly
re-evaluated) is true, and as a convenience binds V to the value of
CND so u can do something with it.

I was a little surprised something like it wasn't already in the
language, and perhaps is a good candidate to add? Or perhaps I missed
an 'easier' way to do the same thing, or perhaps this is 'bad style'
in some way and I'm guilty of imperativism in my thinking.

Example:

(while r (side-effects with many args)
     (pr r))

As opposed to a form more similar to what the macro had to do.


What I like is that:

1) No need to issue LOOP and RECUR and WHEN expressions
2) Many times the binding statements of both RECUR and LOOP seem to be
THE SAME THING, and the above avoids that redundancy

Any thoughts? I somewhat expect someone to point out some obvious api
item i've missed that does the same thing.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to