Clojure:ns resolve->;获取代理->;打电话给我
最小故障情况:Clojure:ns resolve->;获取代理->;打电话给我,clojure,Clojure,最小故障情况: (ns test) (def a (agent "hello")) (send a (fn [x] "world")) ; works (send (ns-resolve 'test 'a) (fn [x] "test")) ; fails 问题: 为什么最后一行失败了 这是代码热加载系统的一部分。我必须使用ns解决方案 有没有办法让这一切顺利进行 谢谢 ns resolve返回一个var,而不是var(代理)的值。您需要取消对var的引用以获取值: (send (der
(ns test)
(def a (agent "hello"))
(send a (fn [x] "world")) ; works
(send (ns-resolve 'test 'a) (fn [x] "test")) ; fails
问题:
为什么最后一行失败了
这是代码热加载系统的一部分。我必须使用ns解决方案
有没有办法让这一切顺利进行
谢谢 ns resolve返回一个var,而不是var(代理)的值。您需要取消对var的引用以获取值:
(send (deref (ns-resolve 'test 'a)) (fn [x] "world"))
;; or
(send @(ns-resolve 'test 'a) (fn [x] "world"))