clojure - Clojure 将 var 添加到命名空间
问题描述
如何将 var 添加到 clojure 命名空间,即以后可以通过调用 ns-interns 来检索它?
这不是(intern ns sym ...),因为实习生创建了一个 var 或重用任何 var sym 绑定的内容。当其他命名空间需要 ns 并保存对 ns 中 var 的引用时,这种区别很重要。我所要求的与 ns-unmap 正好相反。
解决方案
你不能只使用def
吗?:
def
Creates and interns or locates a global var with the name of symbol and a
namespace of the value of the current namespace (*ns*).
在代码中:
(def alpha)
(def beta :boo)
(intern 'tst.demo.core 'gamma :charlie)
(ns-interns 'tst.demo.core)
=> {alpha #'tst.demo.core/alpha,
beta #'tst.demo.core/beta
gamma #'tst.demo.core/gamma}
我不知道你在这里追求什么......?它们看起来都一样。
推荐阅读
- python - 比较数据框中的列和python中匹配的计数频率
- python - 在 Python-Pandas 中使用日期索引的条形图
- vue.js - 在同一个 .gql 文件中使用多个查询时出现 Vetur 错误
- html - 无法从链接下载文件
- python - 移动数据中的非周期性值
- reactjs - 如何使用 Formik 在 ReactJS 中实现单选按钮
- appium - 在机器人框架 Appium 中测试时如何录制屏幕?
- git - 是否可以在多个操作系统之间共享本地 git 存储库?
- java - 从 URL 读取资源并直接返回这些字节作为 REST 请求的响应,Java 7 和 spring MVC 3.2 不存储内存
- android - 用于在多行 edittext 的每一行中设置限制