clojure - 如何确定定义 Clojure 命名空间的完整文件路径?
问题描述
例如:
(defn show-full-path-of-ns [namespace-symbol]
;; how to do it?
)
(show-full-path-of-ns 'ring.middleware.session)
;; => ~/.m2/repository/ring/ring-core/1.7.1/ring-core-1.7.1.jar!ring/middleware/session.clj
(是的,我知道可以将命名空间拆分为多个文件,但我们可能会忽略这一点。)
解决方案
这是该问题的部分解决方案。它适用于类路径中的 jar 文件,但它可能会给你一些想法。
(ns so.find-namespaces
(:require
[clojure.tools.namespace.find :as f]
[clojure.java.classpath :as cp])
(:import
[java.util.jar JarFile]))
(apply hash-map (->> (cp/classpath)
(filter (memfn isFile))
(mapcat #(interleave (f/find-namespaces-in-jarfile (JarFile. %)) (repeat (.getCanonicalPath %))))))
无论如何,如果有解决方案,它可能就在这里
推荐阅读
- python - Discord bot 命令有时有效
- angular - Angular on icon click 切换类名或类名的一部分
- windows - 有没有办法使用cmder过滤Windows中的命令历史记录?
- excel - 同一个工作簿中的两张工作表调试错误?
- c++ - 与在网络编程中使用 Qthread 类相关的错误
- javascript - 更改按钮单击时的背景颜色可切换
- python - 如何组合在一列中具有相同值的熊猫数据框中的行
- c# - 使用 Twilio 从出站呼叫中收集用户输入
- swift - SwiftUI:从列表中删除的行不断重新出现
- sql - 如何比较Oracle和SQL Server之间的大表(亿行)数据