2016-11-05 73 views
-1

这是我的代码。无法解决Clojure中的符号错误?

(use '[leiningen.exec :only (deps)]) 
(deps '[[org.clojure/clojure "1.4.0"] 
     [org.clojure/data.zip "0.1.1"]]) 
(deps '[[clj-http "0.5.8"] 
     [org.clojars.rorygibson/clj-amazon "0.3.0-SNAPSHOT"]] 
) 

(def ACCESS-KEY "my access key") 
(def SECRET-KEY "my secret key") 
(def ASSOCIATE-ID "my id") 

(def ENDPOINT "webservices.amazon.co.uk") 

(def signer (signed-request-helper ACCESS-KEY SECRETE-KEY ASSOCIATE-ID)) 

(def gibson-opus-search (item-search :signer signer :search-index "Books", :keywords "Neuromancer", :associate-tag ASSOCIATE-ID, :condition "New")) 

(def lookup-specific-item (item-lookup :signer signer :associate-tag ASSOCIATE-ID :item-id "B0069KPSPC" :response-group "ItemAttributes,OfferSummary")) 

我想在Clojure上使用亚马逊的产品api。当我在命令提示符上尝试执行lein exec时,我无法在此上下文中解析符号:signed-request helper。我该如何解决这个问题?

+0

您是否使用lein deps代替defproject出于特定原因?该错误表明您的依赖关系未成功包含在内。 – jmargolisvt

回答

1

您从来没有在该环境中定义signed-request-helper,所以当然无法解决。您需要提供一个定义,或者如果它包含在其中一个依赖项中,则需要userequire适当的名称空间。

2

deps调用将设置类路径,以便您的依赖关系可用。您需要使用require命名空间加载它,然后使用refer(在require之内)使这些外部符号可用于您的代码。或者,您可以将use的外部名称空间同时加载到refer(尽管这些日子在风格上通常是不鼓励的)。

在这个例子中:

(require '[clj-amazon.core :refer [signed-request-helper]] 
     '[clj-amazon.product-advertising :refer [item-search item-lookup]) 

或者:

(use 'clj-amazon.core 
    'clj-amazon.product-advertising) 

一般来说,require版本是首选,因为它是用肉眼可追溯凡在你的代码中使用的功能是从哪里来的。

相关问题