简体   繁体   English

java.lang.IllegalArgumentException错误取决于所使用的符号名称-Clojure

[英]java.lang.IllegalArgumentException error depending on symbol names used - Clojure

I am a beginner at Clojure. 我是Clojure的初学者。 I am performing one operation twice, but with changed symbols lang against language 我执行了两次操作,但是对language符号lang进行了更改

One case it is working well, another is throwing an error: java.lang.IllegalArgumentException: No method in multimethod 'my-method' for dispatch value: null 一种情况运行良好,另一种则引发错误: java.lang.IllegalArgumentException: No method in multimethod 'my-method' for dispatch value: null

I am not sure if it is caused by an Clojure syntax or there is something wrong in my linux configuration. 我不确定这是由Clojure语法引起的,还是我的Linux配置有问题。 I have Debian Stretch and boot.clj. 我有Debian Stretch和boot.clj。

The error happens in the terminal. 该错误发生在终端中。 Here you are the both peaces of code an the error: 在这里,您既是代码又是错误:

s@lokal:~$ boot repl
nREPL server started on port 36091 on host 127.0.0.1 - nrepl://127.0.0.1:36091
java.lang.Exception: No namespace: reply.eval-modes.nrepl found
REPL-y 0.4.1, nREPL 0.4.4
Clojure 1.8.0
OpenJDK 64-Bit Server VM 1.8.0_181-8u181-b13-2~deb9u1-b13
        Exit: Control+D or (exit) or (quit)
    Commands: (user/help)
        Docs: (doc function-name-here)
              (find-doc "part-of-name-here")
Find by Name: (find-name "part-of-name-here")
      Source: (source function-name-here)
     Javadoc: (javadoc java-object-or-class-here)
    Examples from clojuredocs.org: [clojuredocs or cdoc]
              (user/clojuredocs name-here)
              (user/clojuredocs "ns-here" "name-here")
boot.user=> (do
       #_=> (defmulti my-method (fn[x] (x "lang")))
       #_=> (defmethod my-method "English" [params] "Hello!")
       #_=> (def english-map {"id" "1", "lang" "English"})
       #_=>     (my-method english-map)
       #_=> )
"Hello!"
boot.user=> 

boot.user=> (do
       #_=> (defmulti my-method (fn[x] (x "language")))
       #_=> (defmethod my-method "English" [params] "Hello!")
       #_=> (def english-map {"id" "1", "language" "English"})
       #_=>     (my-method english-map)
       #_=> )

java.lang.IllegalArgumentException: No method in multimethod 'my-method' for dispatch value: null
boot.user=>

I must add that before it worked with language but not with lang . 我必须补充一点,在它适用于language但不适用于lang It also turned to work or did not when I was changing a my-method symbol name with mymetho-d or greeting . 当我使用mymetho-dgreeting更改my-method符号名称时,它也可以正常工作或无效。

defmulti defines a var, and subsequent calls to defmulti with the same name do nothing, so your second defmulti call is ineffective and the original dispatch function remains. defmulti定义了var和后续调用defmulti具有相同名称的什么都不做,所以你的第二个defmulti调用是无效的,并且原有的调度功能仍然存在。 There's remove-method and remove-all-methods for removing defmethod definitions, but to remove a defmulti definition (without restarting REPL) you can use alter-var-root to set the var to nil: remove-methodremove-all-methods可以删除defmethod定义,但是要删除defmulti定义(无需重新启动REPL),可以使用alter-var-root将var设置为nil:

(defmulti my-method (fn [x] (x "lang")))
(defmethod my-method "English" [params] "Hello!")
(def english-map {"id" "1", "lang" "English"})
(my-method english-map)
=> "Hello!"

(alter-var-root #'my-method (constantly nil)) ;; set my-method var to nil

(def english-map {"id" "1", "language" "English"})
(defmulti my-method (fn [x] (x "language")))
(defmethod my-method "English" [params] "Hello!")
(my-method english-map)
=> "Hello!"

You can use ns-unmap to similar effect: 您可以使用ns-unmap达到类似的效果:

(ns-unmap *ns* 'my-method)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 netty epoll本机在linux(debian)中抛出java.lang.IllegalArgumentException - netty epoll native throw java.lang.IllegalArgumentException in linux(debian) 线程“ main”中的异常java.lang.UnsatisfiedLinkError:未定义的符号:测试 - Exception in thread “main” java.lang.UnsatisfiedLinkError: undefined symbol: Test (Java)编译时出现“错误:找不到符号”? - (Java) “error: cannot find symbol” when compiling? Linux上的java.lang.UnsatisfiedLinkError错误 - java.lang.UnsatisfiedLinkError error on linux Jarsigner错误:java.lang.RuntimeException - Jarsigner error: java.lang.RuntimeException java:符号查找错误:java:未定义的符号:conda环境中的JLI_StringDup - java: symbol lookup error: java: undefined symbol: JLI_StringDup in conda environment Maven:VM java/lang/NoClassDefFoundError: java/lang/Object 初始化期间发生错误 - Maven: Error occurred during initialization of VM java/lang/NoClassDefFoundError: java/lang/Object 当依赖的共享库包含符号时​​,Java JNI“符号查找错误” - Java JNI “symbol lookup error” when a dependent shared library contains the symbol 共享 object 取决于代码中的符号动态链接吗? - Shared object depending on symbol in code dynamically linking it? error = 2,java.lang.ProcessBuilder.start中没有这样的文件或目录 - error=2, No such file or directory at java.lang.ProcessBuilder.start
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM