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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.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
有没有办法在lein repl启动时将方法注入clojure.core?_Clojure - Fatal编程技术网

有没有办法在lein repl启动时将方法注入clojure.core?

有没有办法在lein repl启动时将方法注入clojure.core?,clojure,Clojure,:injections关键字非常有用。不过,我希望在core中动态安装两个函数以进行调试。如何做到这一点 :injections [(require 'spyscope.core) (use '[cemerick.pomegranate :only (add-dependencies)]) (use '[clojure.tools.namespace.repl :only (refresh)])] 理想情况下,我希望r

:injections关键字非常有用。不过,我希望在core中动态安装两个函数以进行调试。如何做到这一点

    :injections [(require 'spyscope.core)
                 (use '[cemerick.pomegranate :only (add-dependencies)])
                 (use '[clojure.tools.namespace.repl :only (refresh)])]

理想情况下,我希望
refresh
能够在任何地方使用它

您可以使用
intern
来实现这一目的,尽管我认为可能有更好的方法让调试功能始终可用。我曾在
intern
clojure.core
一起使用过,我想利用现有函数来学习一些东西,但在其他名称空间中注入函数感觉太粗糙了

(intern 'clojure.core 'refresh (fn [] (println "refreshed!"))
(ns another-ns)
(refresh)
;=> refreshed!
在你的
project.clj
中,你可以特别使用这个键。不过,这取决于您心目中的工作流,因为当REPL启动时,该函数不会在所有已经存在的名称空间中都可用,因为它们都已经在
clojure.core
中引用了公共变量

但是,您可以在repl启动时调用
(clojure.tools.namespace.repl/refresh)
一次,以重新加载所有名称空间,然后该函数应该从此可用。我刚刚尝试了以下方法,似乎效果不错:

:repl-options {:init (do (require 'clojure.tools.namespace.repl)
                         (intern 'clojure.core 'refresh clojure.tools.namespace.repl/refresh)
                         (clojure.tools.namespace.repl/refresh))}