I noticed with-open kind of stuck out because it doesn't use vectors
for binding like let, loop, and others. it was a quick fix using
destructuring to make the macro use square backets
example:
(with-open [f (new java.io.FileWriter "test")] do-stuff)

but as I was writing an email to this list I realized that let,loop,
etc do multiple bindings. so a few hours later I had this:

(defmacro better-with-open [b & f]
  (let [q b
        h (map (fn[x] `(. ~x (close))) (take-nth 2 q))]
    `(let ~q (try [EMAIL PROTECTED] (finally [EMAIL PROTECTED])))))

sorry about all the single letter variables, I am not exaggerating
about how long this took. Still wrapping my head around macros.

usage example:

(better-with-open [f (new java.io.FileWriter "foo" true)
                   q (new java.io.FileWriter "bar")]
                  (. f (write "one"))
                  (. q (write "two")))



-- 
The Mafia way is that we pursue larger goals under the guise of
personal relationships.
    Fisheye

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