1
votes

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

2 Answers

5
votes

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]))
1
votes

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