Hi,

On Mon, Feb 22, 2010 at 02:04:37PM -0500, Alan Dipert wrote:

> (defmacro with-private-fns [[ns fns] & tests]
>   "Refers private fns from ns and runs tests in context."
>     `(let ~(reduce #(conj %1 %2 `(ns-resolve '~ns '~%2)) [] fns)
>          ~...@tests))

Without a deref around the ns-resolve, this stores Vars in the locals.
For functions this is not a problem, because Vars relay invoke to their
contents. However if you have different objects (eg. a map to be used
with get) you will run into trouble.

(defmacro with-private-vars [[ns fns] & tests]
  "Refers private fns from ns and runs tests in context."
  `(let ~(reduce #(conj %1 %2 `@(ns-resolve '~ns '~%2)) [] fns)
     ~...@tests))

Note the @ in front of ns-resolve. Here some illustration of the
problem:

user=> (ns foo.bar)
nil
foo.bar=> (def #^{:private true} x {:a :b :c :d})
#'foo.bar/x
foo.bar=> (in-ns 'user)
#<Namespace user>
user=> (with-private-fns [foo.bar [x]] (x :a))
:b
user=> (with-private-fns [foo.bar [x]] (get x :a))
nil
user=> (with-private-vars [foo.bar [x]] (get x :a))
:b

Sincerely
Meikel

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