Hi Meikel, thank you as always for your help! This makes a lot of
sense. Am I correct in understanding that at some level there is a
separation of var and fn namespace? Or is the need for deref more just
a consequence of the way objects respond with their contents? Please forgive
my ignorance, and thanks in advance for clarification.
Best,
Alan
Excerpts from Meikel Brandmeyer's message of 2010-02-22 15:23:04 -0500:
> 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 [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
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