关于字典:大型哈希图的Clojure单函数自变量?

Clojure single function argument of large hash-map?

我正在尝试解析返回CSV数据(无标头)的旧API的结果。 parse-response函数的效果很好,但是当我尝试使用verify-response进行检查时,却无法使用ArityException Wrong number of args (0) passed to: PersistentHashMap。如何通过一个检查关键字段并创建替代错误哈希图(如果无效)的函数传递哈希图?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
(def response-fields
  [:response_code :response_text
   :address :city :state :zip_code :country
   :phone :fax :email
   :first_name :last_name :company  
   :special_instructions :SpecialCode
   ])

(defn parse-response
 "One line CSV file"
  [response]
  (zipmap response-fields
    (first (csv/read-csv (:body response)))))

(defn verify-response
 "Get response if code is valid"
  [response-map]
  (cond (some? (:response_code response-map)) (response-map)
        :else
        {:response_code"911"
         :response_text"API Failure"}))


verify-response主体中的response-map周围有一组错误的括号。 (response-map)将该映射作为不带参数的函数进行调用。 Clojure中的地图实现了IFn接口;可以使用1或2个参数调用它们,以使用可选的默认值对它们自己进行查找。

1
2
3
4
5
6
user=> ({:a 1} :a)
1
user=> ({:a 1} :b :foo)
:foo
user=> ({:a 1})
;; ArityException Wrong number of args (0) passed to: PersistentArrayMap