【问题标题】:How to make functions from all namespaces available in the .core namespace in Clojure?如何在 Clojure 的 .core 命名空间中使所有命名空间中的函数可用?
【发布时间】:2015-05-25 05:54:00
【问题描述】:

我有一个包含多个命名空间的库。我希望我可以使核心命名空间中的所有命名空间中的函数都可用。这样我就可以只需要example.core 而不是需要example.ns1example.ns2 等。

这是我的核心命名空间中的内容

(ns example.core
  (:require [example.options :refer :all]
            [example.playback :refer :all]
            [example.controlls :refer :all]
            [example.stored :refer :all]
            [example.db :refer :all]))

这就是我试图要求它的方式

(ns test-app.core
  (:require [example.core :as e])

(e/foo) ; where foo is defined in one of the namespaces required by example.core

当我尝试执行时,我得到CompilerException java.lang.RuntimeException: No such var: e/foo

我所追求的可能吗?还是我必须单独导入多个命名空间?

感谢您的宝贵时间

【问题讨论】:

    标签: clojure namespaces


    【解决方案1】:

    您可以使用库 Potemkin 中的 import-vars 来执行此操作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-08-31
      • 2013-03-12
      • 1970-01-01
      • 2023-03-05
      • 2011-03-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多