I want to examine the namespace within a swing thread, as I want to
see if a particular var is defined from another part of the program
before operating on it. However, inside the "do-swing" macro (or just
using SwingUtilities/invokeLater directly) *ns* will always refer to
clojure.core, not the namespace of the file I'm working on.

eg:

(ns some-namespace)
(javax.swing.SwingUtilities/invokeLater (fn [] (println *ns*)))

will print:
#<Namespace clojure.core>

But if I'm defensive and copy *ns*:

(ns other-namespace)
(def this-namespace *ns*)
(javax.swing.SwingUtilities/invokeLater (fn [] (println this-
namespace)))

will print:
#<Namespace other-namespace>
as expected.


Interestingly, all DEF instructions are interned into the expected
namespaces:

other-namespace> (javax.swing.SwingUtilities/invokeLater (fn [] (def
somevar 1)))
nil
other-namespace> somevar
1
other-namespace> clojure.core/somevar
; Evaluation aborted.
other-namespace> other-namespace/somevar
1


Is this expected behaviour?

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