1

How can I test if require is working in clojure. Require in REPL returns nil. I don't know if nil means it worked. The namespace for oauth doesn't seem to set.

Error

Caused by: java.lang.RuntimeException: No such namespace: 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))

2 Answers 2

5

It doesn't work to put your require in your -main function; it must be evaluated when the file is evaluated in order for the namespace alias to be recognized. You should put it in your ns form instead:

(ns hello.core
  (:require [oauth.client :as oauth]
            [twitter]))
Sign up to request clarification or add additional context in comments.

2 Comments

(ns hello.core) (require 'twitter '[oauth.client :as oauth])
@glochild From the require docs: "Use :require in the ns macro in preference to calling this directly."
1

To add to Sam's answer, notice the difference between the repl environment and in a .clj file https://clojuredocs.org/clojure.core/require

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.