On Aug 5, 9:11 pm, Richard Newman <holyg...@gmail.com> wrote:
> > In testing out clojure.contrib.logging within a generated servlet, I
> > noticed that the value of *ns* is always clojure.core, and not the ns
> > of the code.
>
> I have observed this too (running in SailFin, which is based on
> GlassFish).
>
> > Expected response: com.example.servlet
> > Actual response: clojure.core
>
> I don't think so. Remember, this'll print the current binding of *ns*
> when that function is invoked, not at compile time. Counter-example:
>
> user=> (ns foo (:refer-clojure))
> nil
> foo=> (defn bar [] (println *ns*))
> #'foo/bar
> foo=> (bar)
> #<Namespace foo>
> nil
> foo=> (ns baz (:refer-clojure))
> nil
> baz=> (foo/bar)
> #<Namespace baz>
> nil
>
> The important thing is the binding of *ns* in the thread that invokes
> your servlet. I don't know of a way to control that.
>
> -R
Bah! I tried to simplify the example code, and missed conveying the
actual problem. Your example code (and sadly, mine) pulls *ns* at
runtime, the logging macro doesn't; it writes the value of the *ns* at
macro-expansion-time precisely so that it will be the "right" value
when called.
Better example:
foo=> (ns foo (:use (clojure.contrib logging)))
nil
foo=> (defn bar [] (log :fatal "in foo/bar"))
#'foo/bar
foo=> (bar)
#<ag...@72893453:...>
SEVERE: in foo/bar
foo=> (ns baz (:use (clojure.contrib logging)))
nil
baz=> (foo/bar)
SEVERE: in foo/bar
#<ag...@72893453:...>
The same value, "in foo/bar" is printed both times, which is the
desired behavior.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---