如何在不带限定符的所有命名空间中使命名空间中的符号可访问? [英] How to make symbol(s) from namespace accessible in all namespaces w/o qualifier?
问题描述
我有带有调试实用程序的名称空间,该实用程序仅在开发中使用.我想让它们在所有不带限定符的命名空间中均可访问(与clojure.core
中的符号相同).
比方说我的项目结构如下:
dbg_utils.clj :
(ns project.dbg-utils)
(defmacro dbg ...)
db.clj
(ns project.db)
(defn create-entity [...]
...)
我想启动REPL并输入如下内容:
> (require 'project.db)
> (require 'project.dbg-utils)
> (globalize-symbol 'project.dbg-utils/dbg)
并且在不使用限定符的情况下使用dbg
宏后:
(ns project.db) ;; no require of project.dbg-utils
(defn create-entity [...]
(dbg ...) ;; and no qualifier here
...)
是否有类似globalize-symbol
(或接近此)的东西?
Leiningen为此提供了:injections
功能和:user
配置文件.
本文分享了一些有关如何操作的提示那.它基本上是通过将所需的调试功能添加到clojure.core
来工作的,并且由于使用ns
宏时,始终包含此名称空间中的所有公共var(除非另行指定),因此您将在所有名称空间中使用它们. /p>
I have namespace with debug utilities that are used only in development. I'd like to make them accessible in all namespaces without qualifier (same as symbols from clojure.core
).
Let's say my project structure is as follows:
dbg_utils.clj:
(ns project.dbg-utils)
(defmacro dbg ...)
db.clj
(ns project.db)
(defn create-entity [...]
...)
After I'd like to fire up REPL and type something like this:
> (require 'project.db)
> (require 'project.dbg-utils)
> (globalize-symbol 'project.dbg-utils/dbg)
And after use dbg
macro without qualifier:
(ns project.db) ;; no require of project.dbg-utils
(defn create-entity [...]
(dbg ...) ;; and no qualifier here
...)
Is anything like globalize-symbol
(or close to this) available?
Leiningen provides the :injections
feature and the :user
profile for that.
This article shares some pointers on how to do that. It basically works by adding the debugging functions you want to clojure.core
and since all public vars from this namespace are always included when using the ns
macro (unless you specify otherwise), you will have them available in all your namespaces.
这篇关于如何在不带限定符的所有命名空间中使命名空间中的符号可访问?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!