Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.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
*允许未解析变量*在Clojure中做什么?_Clojure - Fatal编程技术网

*允许未解析变量*在Clojure中做什么?

*允许未解析变量*在Clojure中做什么?,clojure,Clojure,就像没有官方文件一样 允许未解决的VAR道歉-这不是一个完整的答案。我还没有弄清楚这件事的一切 *允许未解析的变量*定义在: 并用于: 显然,它在这里的用途是决定当遇到未解析的符号时,是否应立即抛出异常 你可以这样处理它: myns.core=> (ns clojure.core) nil clojure.core=> oops! CompilerException java.lang.RuntimeException: Unable to resolve symbol: oop

就像没有官方文件一样 允许未解决的VAR道歉-这不是一个完整的答案。我还没有弄清楚这件事的一切


*允许未解析的变量*
定义在:

并用于:

显然,它在这里的用途是决定当遇到未解析的符号时,是否应立即抛出异常

你可以这样处理它:

myns.core=> (ns clojure.core)
nil

clojure.core=> oops!
CompilerException java.lang.RuntimeException: Unable to resolve symbol: oops! in this context, compiling:(/tmp/form-init1596111142512149454.clj:1:884) 

clojure.core=> (defn q [] (oops!))
CompilerException java.lang.RuntimeException: Unable to resolve symbol: oops! in this context, compiling:(/tmp/form-init1596111142512149454.clj:1:12) 

clojure.core=> (def *allow-unresolved-vars* true)
Warning: *allow-unresolved-vars* not declared dynamic and thus is not dynamically rebindable, but its name suggests otherwise. Please either indicate ^:dynamic *allow-unresolved-vars* or change the name. (/tmp/form-init1596111142512149454.clj:1)
#'clojure.core/*allow-unresolved-vars*

clojure.core=> oops!
IllegalArgumentException UnresolvedVarExpr cannot be evalled  clojure.lang.Compiler$UnresolvedVarExpr.eval (Compiler.java:1771)
clojure.core=> 

clojure.core=> (defn q [] (oops!))
CompilerException java.lang.VerifyError: (class: clojure/core$q, method: invoke signature: ()Ljava/lang/Object;) Unable to pop operand off an empty stack, compiling:(form-init1596111142512149454.clj:1:1) 

但我还没有弄清楚它的用途,因为未解析的变量仍然会导致错误——它们只是不同的错误。另外,我不理解重新定义时的警告,因为警告说它不是声明为动态的,而在我看来,它在RT.java中似乎是声明为动态的。

似乎只在内部使用,一个省略未解析符号的标志,使编译成为不可操作的。您得到警告是因为您正在重新定义它,而不是设置现有的。您可以使用
altervar root
或者
set,根据上下文修改现有变量。
    if(o == null)
        {
        if(RT.booleanCast(RT.ALLOW_UNRESOLVED_VARS.deref()))
            {
            return sym;
            }
        else
            {
            throw Util.runtimeException("Unable to resolve symbol: " + sym + " in this context");
            }
        }
myns.core=> (ns clojure.core)
nil

clojure.core=> oops!
CompilerException java.lang.RuntimeException: Unable to resolve symbol: oops! in this context, compiling:(/tmp/form-init1596111142512149454.clj:1:884) 

clojure.core=> (defn q [] (oops!))
CompilerException java.lang.RuntimeException: Unable to resolve symbol: oops! in this context, compiling:(/tmp/form-init1596111142512149454.clj:1:12) 

clojure.core=> (def *allow-unresolved-vars* true)
Warning: *allow-unresolved-vars* not declared dynamic and thus is not dynamically rebindable, but its name suggests otherwise. Please either indicate ^:dynamic *allow-unresolved-vars* or change the name. (/tmp/form-init1596111142512149454.clj:1)
#'clojure.core/*allow-unresolved-vars*

clojure.core=> oops!
IllegalArgumentException UnresolvedVarExpr cannot be evalled  clojure.lang.Compiler$UnresolvedVarExpr.eval (Compiler.java:1771)
clojure.core=> 

clojure.core=> (defn q [] (oops!))
CompilerException java.lang.VerifyError: (class: clojure/core$q, method: invoke signature: ()Ljava/lang/Object;) Unable to pop operand off an empty stack, compiling:(form-init1596111142512149454.clj:1:1)