Clojure(加载文件)给出错误(Clojure (load-file) gives an error)
每当我尝试在家用计算机(OSX)上使用(加载文件)时,它会抛出以下错误:
IllegalArgumentException Parameter declaration comp should be a vector clojure.core/assert-valid-fdecl (core.clj:6732)
当我在工作时在我的Windows机器上加载相同的文件时,它可以工作。 抛出错误的(load-file“C:\ clojure \ pc-3.clj”)和(load-file“/Users/myname/clojure/pc-3.clj”)有什么区别? 除了斜杠的路径结构不同,但我不明白为什么这不适用于我的两个系统。
顺便说一下:除了OS,两个系统都运行JRE 1.7_025和clojure-1.5.1。
更新:我被要求进行堆栈跟踪,我不知道如何开始使用Clojure。 但是emacs nrepl-error buffer为我列出了这个:
java.lang.ClassCastException: clojure.lang.PersistentVector cannot be cast to java.lang.String RT.java:318 clojure.lang.RT$3.invoke NO_SOURCE_FILE:1 user/eval278 Compiler.java:6619 clojure.lang.Compiler.eval Compiler.java:6582 clojure.lang.Compiler.eval core.clj:2852 clojure.core/eval main.clj:259 clojure.main/repl[fn] main.clj:259 clojure.main/repl[fn] main.clj:277 clojure.main/repl[fn] main.clj:277 clojure.main/repl RestFn.java:1096 clojure.lang.RestFn.invoke interruptible_eval.clj:56 clojure.tools.nrepl.middleware.interruptible-eval/evaluate[fn] AFn.java:159 clojure.lang.AFn.applyToHelper AFn.java:151 clojure.lang.AFn.applyTo core.clj:617 clojure.core/apply core.clj:1788 clojure.core/with-bindings* RestFn.java:425 clojure.lang.RestFn.invoke interruptible_eval.clj:41 clojure.tools.nrepl.middleware.interruptible-eval/evaluate interruptible_eval.clj:171 clojure.tools.nrepl.middleware.interruptible-eval/interruptible-eval[fn] core.clj:2330 clojure.core/comp[fn] interruptible_eval.clj:138 clojure.tools.nrepl.middleware.interruptible-eval/run-next[fn] AFn.java:24 clojure.lang.AFn.run ThreadPoolExecutor.java:1145 java.util.concurrent.ThreadPoolExecutor.runWorker ThreadPoolExecutor.java:615 java.util.concurrent.ThreadPoolExecutor$Worker.run Thread.java:724 java.lang.Thread.run
更新:找出今天的问题。 我遇到了与我的Windows框完全相同的问题,原来的答案是正确的,但我认为它与(加载文件)有关的错误。 我加载的文件有一个函数,它不使用vector []作为函数本身的一部分。 当加载文件检查语法以确保文件中的所有内容都已完成时,Clojure正在做正确的事情(但我完全忘记了这一点)。 我的功能不是这样,它不会加载文件。 我忘了LISP这样做,这是一个特征而不是一个bug(我之所以喜欢LISP)。
我是新手,但不是LISP,我应该意识到这一点。 该文件是我的学习档案。 我从REPL重新输入的所有示例为什么要学习并使用最新版本重新加载文件以确保我输入正确的文件。 看来,当我将最新的函数添加到文件时,我重新输入错误并且没有重新加载文件来检查它。 当我离开并关闭REPL然后在晚餐后回来并试图重新加载文件它不会加载。
很抱歉浪费时间。 但感谢你的帮助,也很快。 原来的答案是对的,我只是忘了重新检查文件中的所有功能。
Whenever I try to use (load-file) on my home computer (OSX) it throws the following error:
IllegalArgumentException Parameter declaration comp should be a vector clojure.core/assert-valid-fdecl (core.clj:6732)
When I load the same file on my Windows box at work it works. What is the difference between (load-file "C:\clojure\pc-3.clj") and (load-file "/Users/myname/clojure/pc-3.clj") that is throwing the error. Other than the path structure with the slashes is different but I don't understand why this is not working on my both systems.
BTW: Other than OS both systems are running JRE 1.7_025 with clojure-1.5.1.
UPDATE: I was asked for a stack trace and I'm not sure how to do this just started working with Clojure. But emacs nrepl-error buffer listed this out for me:
java.lang.ClassCastException: clojure.lang.PersistentVector cannot be cast to java.lang.String RT.java:318 clojure.lang.RT$3.invoke NO_SOURCE_FILE:1 user/eval278 Compiler.java:6619 clojure.lang.Compiler.eval Compiler.java:6582 clojure.lang.Compiler.eval core.clj:2852 clojure.core/eval main.clj:259 clojure.main/repl[fn] main.clj:259 clojure.main/repl[fn] main.clj:277 clojure.main/repl[fn] main.clj:277 clojure.main/repl RestFn.java:1096 clojure.lang.RestFn.invoke interruptible_eval.clj:56 clojure.tools.nrepl.middleware.interruptible-eval/evaluate[fn] AFn.java:159 clojure.lang.AFn.applyToHelper AFn.java:151 clojure.lang.AFn.applyTo core.clj:617 clojure.core/apply core.clj:1788 clojure.core/with-bindings* RestFn.java:425 clojure.lang.RestFn.invoke interruptible_eval.clj:41 clojure.tools.nrepl.middleware.interruptible-eval/evaluate interruptible_eval.clj:171 clojure.tools.nrepl.middleware.interruptible-eval/interruptible-eval[fn] core.clj:2330 clojure.core/comp[fn] interruptible_eval.clj:138 clojure.tools.nrepl.middleware.interruptible-eval/run-next[fn] AFn.java:24 clojure.lang.AFn.run ThreadPoolExecutor.java:1145 java.util.concurrent.ThreadPoolExecutor.runWorker ThreadPoolExecutor.java:615 java.util.concurrent.ThreadPoolExecutor$Worker.run Thread.java:724 java.lang.Thread.run
UPDATE: Found out what the problem was today. I was having the exact same problem with my Windows box turns out that the original answer was correct but my assumption that it had to do with (load-file) was incorrect. The file I was loading had a function that was not using a vector [] as part of the function itself. Clojure was doing the correct thing (but I totally forgot about this) when loading the file checking the syntax to make sure that everything was complete in the file. My function wasn't so it wouldn't load the file. I forget that LISPs do this and that it's a feature not a bug (reason why I like LISPs).
I'm new to clojure but not to LISPs and I should have realized this. The file is my study file. All the examples I retype from the REPL why studying and the reload the file with the newest to make sure I typed it in correct. It appears that when I added the newest function to file I retyped it incorrect and didn't reload the file to check it. When I went away and closed down the REPL and then came back after dinner and tried to reload the file it wouldn't load.
So sorry for being a waste of time. But thanks for the help, and quickly too. The original answer was correct I just forgot to recheck all the functions in the file.
最满意答案
该错误表明编译器正在处理类似的事情
(defn function-name comp (do-stuff ...))
也许
(defn [arg1] comp (do-stuff ...))
代替
(defn function-name [comp] (do-stuff ...))
load-file
接受一个字符串而不是一个vector(load-file "path/to/file.clj)
两个系统上的代码是不一样的?
路径解释/
vs\
导致其他东西被加载吗?That error indicates that the compiler was processing something like
(defn function-name comp (do-stuff ...))
or perhaps
(defn [arg1] comp (do-stuff ...))
instead of
(defn function-name [comp] (do-stuff ...))
load-file
takes a string not a vector(load-file "path/to/file.clj)
Could it be that the code is not the same on the two systems?
Could there be a difference in path interpretation/
vs\
causing something else to get loaded?
相关问答
更多-
这个问题已在IDEA 13的插件中修复,对于IDEA 12插件(以及解决方法),请参阅http://youtrack.jetbrains.com/issue/CLJ-237 Finally, I've found that was a Maven issue with the clojure plugin. I've added this configuration to the pom.xml, and then it worked.
c ... -
Emacs Predule发布了nrepl.el而不是swank-clojure。 你需要安装nrepl-ritz而不是swank-ritz。 Swank-clojure是一个死的项目,在clojure-mode 2.0.0(Predule附带的那个)中不再支持。 Emacs Predule ships nrepl.el instead of swank-clojure. You need to install nrepl-ritz instead of swank-ritz. Swank-clojure ...
-
project.clj确实不知道在哪里寻找foo / defproject。 所以,如果你在repl上,你可以做 user> (in-ns 'foo) foo> (read-project "project.clj") 这将从foo名称空间中的project.clj运行代码,其中定义了defproject。 或者你可以在project.clj中放置(in-ns'foo)。 结果将是相同的。 但是你也可以在project.clj中写这样的东西: (foo/defproject ...) 当你运行(foo ...
-
我最好的猜测是你需要用命令lein uberjar来建立这个项目。 这个序列起作用: $ lein new luminus foobar Retrieving ... Generating a Luminus project. $ cd foobar $ lein uberjar Retrieving ... Compiling foobar.session Compiling foobar.layout Compiling foobar.handler Compiling foobar.routes.h ...
-
导致错误的是classpath(用于启动Clojure REPL的那个)不包括clojure.tools.logging库。 Test.clj需要它,所以REPL在加载时无法找到所需的包,因此错误。 我不确定你是如何启动REPL的,但是答案的其余部分假定这是终端中的常规REPL(不是来自IntelliJ IDEA本身;如果REPL是从IntelliJ IDEA启动的 - 我会说它是错误配置最后一个,因为它应该使用正确的项目类路径启动REPL - 首先要检查的是项目配置。 因此,为了解决这个问题,请确保REP ...
-
使用macroexpand和朋友来帮助调试 (def form (quote (safe [s (FileReader. (java.io.File. "test.txt"))] (. s read)))) (pprint (macroexpand form)) ;=> (let* [s (FileReader. (java.io.File. "test.txt"))] (try (user/safe [] (. s read)) ; <--- Macro is recursive (cat ...
-
确定为什么Clojure REPL(加载文件)和蛋糕构建产量错误(Determining Why Clojure REPL (load-file) and cake build yield error)[2022-10-26]
我认为你的命名空间声明的“语法”有问题。 相反,试试这个: (ns mr1 (:use [clojure.string :only [split]] [clojure.string :only [join]])) 相应地改变你的:project.clj中的主要设置:它应该只是mr1 ,与我前面所说的相反。 根据googolplex的评论编辑 I think there is something wrong with the "syntax" of your namespace ... -
以下代码在保存后加载.emacs或~/.emacs.d/init.el文件: (defun my-load-user-init-file-after-save () (when (string= (file-truename user-init-file) (file-truename (buffer-file-name))) (let ((debug-on-error t)) (load (buffer-file-name))))) (add-h ...
-
该错误表明编译器正在处理类似的事情 (defn function-name comp (do-stuff ...)) 也许 (defn [arg1] comp (do-stuff ...)) 代替 (defn function-name [comp] (do-stuff ...)) load-file接受一个字符串而不是一个vector (load-file "path/to/file.clj)两个系统上的代码是不一样的? 路径解释/ vs \导致其他东西被加载吗? That error indica ...
-
load-file函数最终到达Compiler.java#L7395 ,它动态地将源名称(当它存在时)绑定到SOURCE指定的变量(参见Compiler.java#L235 ),又名clojure.core/*source-path* 。 在/tmp/test.clj : (print clojure.core/*source-path*) 在REPL中: user=> (load-file "/tmp/test.clj") test.cljnil The load-file function even ...