如何从另一个名称空间卸载函数? [英] How to unload a function from another namespace?
本文介绍了如何从另一个名称空间卸载函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从命名空间学习中加载了函数 say-hi
I load a function say-hi
from namespace learning.greeting
(use 'learning.greeting)
当我尝试重新定义say-hi函数时在当前(用户)命名空间下,出现错误:
When I try to re-defn the say-hi function under the current (user) namespace, I got the error:
CompilerException java.lang.IllegalStateException: say-hi already refers to: #'learning.greeting/say-hi in namespace: user, compiling:(NO_SOURCE_PATH:1:1)
那么如何从其他名称空间中卸载该函数?
So how to unload the function from other namespaces?
推荐答案
如果您希望摆脱REPL上另一个命名空间到Var的直接映射,请说
If you want to get rid of a direct mapping to a Var from another namespace at the REPL, say
(ns-unmap 'current-namespace 'local-alias)
示例:
user=> (ns-unmap *ns* 'reduce)
nil
user=> (reduce + 0 [1 2 3])
CompilerException java.lang.RuntimeException: Unable to resolve symbol: reduce in this context, compiling:(NO_SOURCE_PATH:2:1)
如果使用:rename
,本地别名将与Var的实际名称不同:
Local alias will differ from the actual name of the Var if :rename
was used:
(use '[clojure.walk
:only [keywordize-keys]
:rename {keywordize-keys keywordize}])
要删除所有指向 clojure中的Vars的映射。步行
:
(doseq [[sym v] (ns-map *ns*)]
(if (and (var? v)
(= (.. v -ns -name) 'clojure.walk))
(ns-unmap *ns* sym)))
这篇关于如何从另一个名称空间卸载函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文