On Feb 15, 12:03 pm, Аркадий Рост <arkr...@gmail.com> wrote:
> oh wait...I take a look on binding and with-binding* 
> realesation.http://github.com/richhickey/clojure/blob/f4c58e3500b3668a0941ca21f9a...
> Why with-binding* function wasn't write like this:
> (defn with-bindings*
>   [bindings f & args]
>   (assert-args binding
>     (vector? bindings) "a vector for its binding"
>     (even? (count bindings)) "an even number of forms in binding
> vector")
>   (let [var-ize (fn [var-vals]
>                   (loop [ret [] vvs (seq var-vals)]
>                     (if vvs
>                       (recur (conj (conj ret `(var ~(first vvs)))
> (second vvs))
>                              (next (next vvs)))
>                       (seq ret))))]
>   (push-thread-bindings (hash-map ~@(var-ize bindings)))
>   (try
>     (apply f args)
>     (finally
>       (pop-thread-bindings))))

That function is very confused. You're trying to use a splice outside
of a syntax-quote which will not work. Even if you called simply "(var-
ize bindings)",  you would end up calling something like (push-thread-
bindings (hash-map (quote [(var 3) something, (var "blah")
something]))) because the bindings vector is evaluated.

The binding operator is a macro, and it can work with the symbols
passed to it and transform the input to code that uses the var
operator, but the with-bindings* operator is a function, which means
it can't use var on its parameters. If you wanted to pass symbols to
with-bindings*, you would have to do it like (with-bindings* ['a 3, 'b
4]) and the functions would have to use resolve internally to
transform the vector into a map of vars to bindings.

As far as I can tell, binding could be implemented using with-bindings
like so:

(defmacro binding [bindings & body]
  ; var-ize elided; assume it exists
  `(with-bindings*
     ~(apply hash-map (var-ize bindings))
     (fn [] ~...@body)))

--
Jarkko

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