On May 12, 2009, at 12:30 PM, Andrew Wagner wrote:
It seems like this idiom would be easy to implement in this macro. Or am I missing something?
The current implementation of clojure.core/with-open works with multiple bindings the way you're advocating. The one in the article makes for an easier to understand example. As I recall, it's an older version before Clojure changed to use vectors for binding forms pervasively.
--Steve Clojure 1.1.0-alpha-SNAPSHOT user=> (doc with-open) ------------------------- clojure.core/with-open ([bindings & body]) Macro bindings => [name init ...] Evaluates body in a try expression with names bound to the values of the inits, and a finally clause that calls (.close name) on each name in reverse order. nil user=> (source with-open) (defmacro with-open "bindings => [name init ...] Evaluates body in a try expression with names bound to the values of the inits, and a finally clause that calls (.close name) on each name in reverse order." [bindings & body] (assert-args with-open (vector? bindings) "a vector for its binding"(even? (count bindings)) "an even number of forms in binding vector")
(cond (= (count bindings) 0) `(do ~...@body) (symbol? (bindings 0)) `(let ~(subvec bindings 0 2) (try (with-open ~(subvec bindings 2) ~...@body) (finally (. ~(bindings 0) close)))) :else (throw (IllegalArgumentException. "with-open only allows Symbols in bindings")))) nil user=>
smime.p7s
Description: S/MIME cryptographic signature