这是我正在使用的代码,我在其中创建记录,然后尝试修改它们:
(defrecord Record [Name Age Index ClassIndex])
(defn read-csv [fname count]
(with-open [file (io/reader fname)]
(doall (map #(str/split % #",") ;; doesn't work with commas in text fields
(take count (line-seq file))))))
(defn make-record [idxs types row]
(apply ->Record
(map (fn [idx t]
(let [value (nth row idx)]
(case t
:string value
:int (Integer/parseInt value)
:long (Long/parseLong value))))
idxs types)))
(def records
(doall (map (partial make-record
[0 1 2 3]
[:string :int :long :int])
(read-csv "C:/Users/user/Documents/URECA/hi/lib/test.csv" 1))))
(reset! records
(map #(assoc % :ClassIndex
(+ (:Age %) (:Index %)) :Age (+ 1 :Age %))
@records))
当我运行这段代码时,我得到了这个异常:
ClassCastException clojure.lang.LazySeq cannot be cast to
clojure.lang.IDeref clojure.core/deref (core.clj:2080)
为什么我会收到此错误?
更新以回应评论:
我有一张记录地图,我想更新这些记录。该类:Index
将由:Age
+的值确定:Index
。:Age
但是,和的初始值:Index
将从文件中读取。