Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Function 我有一个Clojure seq,包含3个函数。为什么(其余我的序号)会给出一个“答案”;不能被转换为;例外?_Function_Debugging_Clojure_Tail Recursion - Fatal编程技术网

Function 我有一个Clojure seq,包含3个函数。为什么(其余我的序号)会给出一个“答案”;不能被转换为;例外?

Function 我有一个Clojure seq,包含3个函数。为什么(其余我的序号)会给出一个“答案”;不能被转换为;例外?,function,debugging,clojure,tail-recursion,Function,Debugging,Clojure,Tail Recursion,在调试一个更大的函数的过程中,我创建了一个更简单的函数来测试错误的位置: (defn foo [a-val p1 p2 & rest] (loop [curr-preds (cons p1 (cons p2 rest))] (let [first-pred (first curr-preds) first-bool (first-pred a-val) second-bool ((second curr-preds) a-

在调试一个更大的函数的过程中,我创建了一个更简单的函数来测试错误的位置:

(defn foo [a-val p1 p2 & rest]
  (loop [curr-preds   (cons p1 (cons p2 rest))]
    (let [first-pred   (first curr-preds)
          first-bool   (first-pred a-val)
          second-bool  ((second curr-preds) a-val)
          third-bool  ((last curr-preds) a-val)]
      (println "\n\nLogical values: " first-bool second-bool third-bool)
      (println "Is it a seq?"  (seq? curr-preds))
      (if (empty? curr-preds)
        first-bool
        #_(recur (rest curr-preds))
          ))))
p1、p2和rest中的函数集合都是谓词(例如,奇数?)。我写这篇文章的目的是希望它总是用3个谓词来调用

当我取出最后一行下一行的
35;
时,我得到以下错误:

java.lang.ClassCastException: clojure.lang.ArraySeq cannot be cast to clojure.lang.IFn
/Users/gr/temp/LTtemp1.clj:166 user/foo
          RestFn.java:467 clojure.lang.RestFn.invoke
通过
println
语句,我发现:

  • curr preds是一个
    seq
    ,如预期的那样包含3个谓词

  • a-val
    上调用每个pred将返回预期结果

  • curr preds
    实际上是一个
    seq


我的问题是:
rest
被定义为在seqs上工作,那么为什么我会得到上述不能转换的错误?谢谢。

您有一个名为
rest
的本地文件,它由函数参数列表绑定。你试图调用
rest
就好像它是一个函数,而不是调用
clojure.core/rest

哎哟!我很尴尬,我犯了这个错误…我一直在努力解决这个问题。现在我可以继续下一个错误了。。。。非常感谢。每个人都至少犯过一次这样的错误。当你做了十几次,你可能会感到尴尬。