简体   繁体   English

Clojure repl-如何确保:reload-all确实会重新加载所有必需的名称空间?

[英]Clojure repl - how can I insure that :reload-all does indeed reload all required namespaces?

There is an odd and very annoying, not to say often time-consuming, behaviour in the lein REPL. 在lein REPL中,有一种奇怪且非常烦人的行为,更不用说经常耗时了。

Namely, if I use :reload-all with a namespace, and a namespace required by it has an error, the repl doesn't tell me a thing about it. 也就是说,如果我将:reload-all与命名空间一起使用,并且它所需的命名空间有错误,则repl不会告诉我有关此事。 It just takes the last valid build of said namespace and doesn't inform me that it did so. 它只是采用了上述命名空间的最后一个有效构建,而没有通知我这样做了。

Obviously, in most situations this is extremely unsatisfactory. 显然,在大多数情况下,这是非常不令人满意的。 Because I wouldn't use :reload-all if none of the required namespaces had changed, and if they did and contain an error, I would very much like to know about it, and not suddenly wonder why the code I'm executing in the REPL seems to do something completely different than the code I'm having on my screen. 因为如果所有必需的名称空间都没有更改,并且如果它们发生更改并包含错误,我将不使用:reload-all,我非常想了解它,而不会突然想知道为什么我要在其中执行的代码REPL似乎所做的事情与屏幕上显示的代码完全不同。

Is there a way to force this behavior? 有没有办法强制这种行为?

tools.namespace library may help you. tools.namespace库可能会为您提供帮助。

There are known issues with reloading code via (require ... :reload) or (require ... :reload-all) . 通过(require ... :reload)(require ... :reload-all)重新加载代码存在已知问题 Therefore, instead of require , try using clojure.tools.namespace/refresh : 因此,请尝试使用clojure.tools.namespace/refresh而不是require

user> (clojure.tools.namespace.repl/refresh)

It will scan your project for files/namespaces that have changed and will reload them and their dependencies in correct order. 它将在您的项目中扫描已更改的文件/命名空间,并以正确的顺序重新加载它们及其依赖项。

refresh will report about errors in dependent namespaces during reload. 在重新加载期间, refresh报告有关从属命名空间中的错误

Also, read about requirements for your code to use this library and potential issues . 另外,请阅读有关使用此库的代码要求潜在问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM