Clojure编译器错误

0 compiler-errors clojure

我正在开发一个包含以下代码行的clojure程序:

(defn makeStruct 
 "Take a line of input and return a starbucks-struct"
 [input]
 (let[(apply struct storeinfo (clojure.string/split input #","))]
 )
Run Code Online (Sandbox Code Playgroud)

)

我得到这个编译器错误:

Exception in thread "main" java.lang.IllegalArgumentException: let requires an even number of forms in binding vector (clojureHW.clj:24)
Run Code Online (Sandbox Code Playgroud)

我对clojure很新,并不完全确定我在做什么,但在这种情况下,输入是一个字符串,我将它拆分为一个向量来初始化我的结构.我使用的语法let不正确吗?

Mic*_*ent 5

let需要偶数个表单,因为它将值绑定到本地:

(let [x 10,
      y (+ x 20)]
   ; do something with x and y here
   (* x y))
Run Code Online (Sandbox Code Playgroud)

请阅读此处的文档:http: //clojure.org/special_forms#Special%20Forms--(let%20%5Bbindings*%20%5D%20exprs*)

  • (apply struct storeinfo)不是符号,就像我给你的例子中的x或y一样.顺便说一句,你有(应用struct storeinfo(clojure.string/split input#",")),而不是(应用struct storeinfo)和(split input#","). (2认同)