2

我有以下 clojure 代码(尝试从 redis 写入/获取条目):

(ns hello.core2)
(ns h hello.core2 (:require [taoensso.carmine :as car]))

(def pool (car/make-conn-pool))
(def spec-server1 (car/make-conn-spec))
(defmacro wcar [& body] `(car/with-conn pool spec-server1 ~@body))`

(defn -main
  (wcar (car/ping)
    (car/set "foo" "bar")
    (car/get "foo")))

我收到以下错误:

Exception in thread "main" java.lang.IllegalArgumentException: Don't know how to create ISeq from: clojure.lang.Symbol
    at clojure.lang.RT.seqFrom(RT.java:487)
    at clojure.lang.RT.seq(RT.java:468)

知道我做错了什么吗?

4

2 回答 2

7

(defn -main ...):你忘记了函数的参数向量-main;它应该是(defn -main [& args] ...)

于 2013-05-05T20:57:47.913 回答
6

问题大概是这样的:

(ns h hello.core2 (:require [taoensso.carmine :as car]))

应该只有一个命名空间声明,像这样(所以也移动第一个 ns 表达式):

(ns hello.core2
  (:require [taoensso.carmine :as car]))
于 2013-05-05T18:53:44.000 回答