Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
有没有办法拿到clojure所有手表的钥匙_Clojure - Fatal编程技术网

有没有办法拿到clojure所有手表的钥匙

有没有办法拿到clojure所有手表的钥匙,clojure,Clojure,如果有一个原子: (def a (atom {})) 设置以下手表 (add-watch a :watcher println) (add-watch a :watcher2 println) 有这样的函数吗 (get-watches a) ;; => [:watcher :watcher2] (atom{})创建类型为clojure.lang.atom的对象,该对象扩展了实现接口的抽象类。IRef声明在中实现的方法 以下是解决方案: (def a (atom {})) (add-w

如果有一个原子:

(def a (atom {}))
设置以下手表

(add-watch a :watcher println)
(add-watch a :watcher2 println)
有这样的函数吗

(get-watches a)
;; => [:watcher :watcher2]
(atom{})
创建类型为
clojure.lang.atom
的对象,该对象扩展了实现接口的抽象类。IRef声明在中实现的方法

以下是解决方案:

(def a (atom {}))
(add-watch a :watcher println)
(println (-> a .getWatches keys))
奇怪的是,
clojure.core
没有
get手表
。镜像
addwatch
我们得到的实现:

(defn get-watches 
  "Returns list of keys corresponding to watchers of the reference."
  [^clojure.lang.IRef reference] 
  (keys (.getWatches reference)))


Ivan的答案对于JVM上的Clojure来说非常好。以下是您在ClojureScript中的操作方式:

(按键(.-a))

(:watches (bean a))
(keys (:watches (bean a)))