【问题标题】:clojure require isn't setting the namespace oauthclojure require 没有设置命名空间 oauth
【发布时间】:2016-08-22 12:50:20
【问题描述】:

如何测试 require 是否在 clojure 中工作。 REPL 中的 Require 返回 nil。我不知道 nil 是否意味着它有效。 oauth 的命名空间似乎没有设置。

错误

原因:java.lang.RuntimeException:没有这样的命名空间:oauth

(ns hello.core)
(defn -main
  []

  (require 'twitter '[oauth.client :as oauth])

  ;; Make a OAuth consumer
  (def oauth-consumer (oauth/make-consumer <key>
                                           <secret>
                                           "https://api.twitter.com/oauth/request_token"
                                           "https://api.twitter.com/oauth/access_token"
                                           "https://api.twitter.com/oauth/authorize"
                                           :hmac-sha1))

【问题讨论】:

    标签: clojure


    【解决方案1】:

    require 放在-main 函数中是行不通的;为了识别命名空间别名,必须在评估文件时对其进行评估。你应该把它放在你的ns 表单中:

    (ns hello.core
      (:require [oauth.client :as oauth]
                [twitter]))
    

    【讨论】:

    • (ns hello.core) (需要 'twitter'[oauth.client :as oauth])
    • @glochild 来自require 文档:“在ns 宏中使用:require,而不是直接调用它。”
    【解决方案2】:

    要添加到 Sam 的答案,请注意 repl 环境和 .clj 文件中的区别 https://clojuredocs.org/clojure.core/require

    【讨论】:

      猜你喜欢
      • 2021-06-05
      • 2011-08-31
      • 1970-01-01
      • 2012-07-21
      • 2011-03-29
      • 1970-01-01
      • 2016-02-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多