Linux 参数声明列表。应该是Clojure中的向量

Linux 参数声明列表。应该是Clojure中的向量,linux,ubuntu,clojure,Linux,Ubuntu,Clojure,我试着为我的班级做CS实验,但每次我试着运行我的测试和代码时,我的代码永远不会加载。它显示以下错误: Exception in thread "main" java.lang.IllegalArgumentException: Parameter declaration List. should be a vector at clojure.core$assert_valid_fdecl.invoke(core.clj:6567) at clojure.core$sigs.invoke(core

我试着为我的班级做CS实验,但每次我试着运行我的测试和代码时,我的代码永远不会加载。它显示以下错误:

Exception in thread "main" java.lang.IllegalArgumentException: Parameter declaration List. should be a vector
at clojure.core$assert_valid_fdecl.invoke(core.clj:6567)
at clojure.core$sigs.invoke(core.clj:220)
at clojure.core$defn.doInvoke(core.clj:294)
at clojure.lang.RestFn.invoke(RestFn.java:494)
at clojure.lang.Var.invoke(Var.java:431)
at clojure.lang.AFn.applyToHelper(AFn.java:178)
at clojure.lang.Var.applyTo(Var.java:532)
at clojure.lang.Compiler.macroexpand1(Compiler.java:6366)
at clojure.lang.Compiler.macroexpand(Compiler.java:6427)
at clojure.lang.Compiler.eval(Compiler.java:6495)
at clojure.lang.Compiler.load(Compiler.java:6952)
at clojure.lang.RT.loadResourceScript(RT.java:359)
at clojure.lang.RT.loadResourceScript(RT.java:350)
at clojure.lang.RT.load(RT.java:429)
这是我的密码对不起,伙计们。我不知道怎么了,我觉得一切都很好

(ns linked_list_lab.core)

;; We start with a defrecord.  In traditional lisps, the
;; first element of a list is called the "car", standing for
;; "Contents of Address Register," the name of the register where
;; it was stored.  The pointer to the rest of the list was called
;; the "cdr," for "Contents of Decrement Register", and is pronounced
;; "could-er".

(defrecord Cons [car cdr])

;; One problem with singly linked lists is that finding the length is
;; expensive $${\cal O}(n)$$.  We can use a wrapper class to deal with
;; that.  Here we have a `List` record that keeps a pointer to the list
;; along with the size.

(defrecord List [data size])

;; The `make-list` function just creates an empty list.

(defn make-list
  "Create an empty list."
  (List. nil 0))

;; The `insert-front` function shows a special syntax Clojure has.
;; If you know the argument to your function should be a record or a
;; hash-map, you can use this pattern-matching syntax as a shorthand.
;; Here we have `{:keys [data size]}`, which will create new variables
;; `data` and `size`.  So if I pass in `{:data 10 :size 20}`, then
;; `data` will be given 10, and `size` will be given 20.
;; This is often called "destructuring".

;; Test broke-1 will not increment the size.
;; Test broke-2 will forget to do the cons.
;; Test broke-3 will replace the cons and not point to the next one.

(defn insert-front 
  "Insert an element at the beginning of the list."
  [{:keys [data size]} new-elt]
  (List. (Cons. new-elt data) (+ 1 size))) 

;; Here are some utility functions that convert Clojure lists to
;; our Cons. record, and vice-versa.  The broke versions will not
;; mess with these.

(defn list-to-cons
  [xx]
  (cond (empty? xx) nil
        :else       (Cons. (first xx) (list-to-cons (next xx)))))

 (defn cons-to-list
  [xx]
  (cond (nil? xx)   '() 
        :else       (cons (:car xx) (cons-to-list (:cdr xx)))))

;; The `insert-sorted` function assumes that the elements are orderable
;; and puts the element in the spot that will preserve the ordering.

;; Test broke-4 will use `(Cons. elt (:cdr xx))` in the third case.
;; Test broke-5 will use `(Cons. (:car xx) nil)` in the second case.

(defn insert-ordered-cons
  "Insert the element `elt` into an ordered `Cons.` chain.
This is used by `insert-ordered`."
  [elt xx]
  (cond (empty? xx) (Cons. elt nil)
        (> elt (:car xx)) (Cons. (:car xx) (insert-ordered-cons elt (:cdr xx)))
        :fine-be-that-way (Cons. elt xx)))

(defn insert-ordered
  "Insert an element into an ordered list."
  [{:keys [data size]} new-elt]
  (List. (insert-ordered-cons new-elt data) (+ size 1)))

;; The `delete` function will delete one element from the list.

;; Test broke-6 will truncate the list past the deletion point.
;; Test broke-7 will forget to decrement the size.
;; Test broke-8 will always decrement the size, even if the element is not found.

(defn delete
  "Delete `elt` from `xx`."
  [elt xx]
   (cond (empty? xx) nil
       (= elt (:car xx)) (:cdr xx)
        :else (Cons. (:car xx) (delete elt (:cdr xx))) )
  )

;; The `delete-all` function will delete all copies of elt from xx.

;; Test broke-9 will delete only one copy.
;; Test broke-10 will decrement the count instead of properly subtracting the
;;      number of deletions.

(defn delete-all
  "Delete all occurrences of `elt` from `xx`."
  [elt xx]
  (cond (empty? xx) nil
      (= elt (:car xx))  (delete-all elt (:cdr xx))
        :else (Cons. (:car xx) (delete-all elt (:cdr xx)))
        )
  )

您正在执行一个没有参数列表的defn。

您正在执行一个没有参数列表的defn。

函数make list遗漏了一个参数声明向量

(defn make-list
  [] ;; <- fix
  ...)
函数生成列表缺少参数声明向量

(defn make-list
  [] ;; <- fix
  ...)

通常,显示您的代码,而不仅仅是错误。此外,就编写好的问题而言,还应显示参数声明列表的标题。在Clojure中应该是一个向量会比我不理解这个错误的含义有用得多。。。林克建议,解决这类神秘问题的第一步是尝试分别评估代码的不同部分,无论是在REPL中,还是通过注释或删除部分。通常,您会通过这种方式发现解决方案。如果您这样做了,您就会知道问题出在生成列表的def上,即使您仍然不知道问题出在哪里。此时,您可以问一个更具体的问题。ns linked_list_lab.core可能应该是ns linked-list-lab.core。这里描述了这种特性:库名称中的连字符被路径中的下划线替换。通常,显示代码,而不仅仅是错误。此外,在编写好问题方面,参数声明列表的标题。在Clojure中应该是一个向量会比我不理解这个错误的含义有用得多。。。林克建议,解决这类神秘问题的第一步是尝试分别评估代码的不同部分,无论是在REPL中,还是通过注释或删除部分。通常,您会通过这种方式发现解决方案。如果您这样做了,您就会知道问题出在生成列表的def上,即使您仍然不知道问题出在哪里。此时,您可以问一个更具体的问题。ns linked_list_lab.core可能应该是ns linked-list-lab.core。这里描述了这种特性:库名称中的连字符在pathOh my god中被下划线取代!!非常感谢你。我不敢相信我错过了。这是Clojure有史以来最好的建议!!!哦,我的上帝!!非常感谢你。我不敢相信我错过了。这是Clojure有史以来最好的建议!!!