Oh, it's just significantly harder to read if you don't know clojure, that's
all.

On Tue, May 12, 2009 at 2:43 PM, Emeka <emekami...@gmail.com> wrote:

> Why?
>
>
> On Tue, May 12, 2009 at 5:37 PM, Andrew Wagner <wagner.and...@gmail.com>wrote:
>
>> Wow. Ok, yeah, I'm glad he didn't put that version in the article :)
>>
>>
>> On Tue, May 12, 2009 at 1:17 PM, Stephen C. Gilardi <squee...@mac.com>wrote:
>>
>>>
>>> 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=>
>>>
>>>
>>
>>
>>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
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 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to