On Tue, Nov 24, 2009 at 12:01 PM, kony <[email protected]> wrote:

> Hi,
>
> I found that resolve does not work correctly (I guess) when it is
> called from other thread than main:
>
> e.g.
>
> let define
>
> (def zz 123)
>
> and afterwords call:
>
> (.start (new Thread #(println (resolve 'zz))))
>
> for me it does not work (it returns nil)
>


This is because the spawned thread isn't in the current namespace:
user=> (.start (Thread. #(println *ns*)))
nil
#<Namespace clojure.core>

So you have to capture a reference to your current ns one way or the other.
Some examples:
(.start (let [ns *ns*] (Thread. #(binding [*ns* ns] (println (resolve
'zz))))))
or
(.start (let [ns *ns*] (Thread. #(println (ns-resolve ns 'zz)))))
or
(.start (let [resolve (partial ns-resolve *ns*)] (Thread. #(println (resolve
'zz)))))

Note that if your symbol is namespaced that simply works:
(.start (Thread. #(println (resolve 'user/zz))))
or, simpler:
(.start (Thread. #(println (resolve `zz)))) ; a backquote

hthn

Christophe


-- 
Professional: http://cgrand.net/ (fr)
On Clojure: http://clj-me.cgrand.net/ (en)

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

Reply via email to