苹果酒代表中的宏(例如 - >)

Ant*_*ald 1 emacs clojure cider

为什么使用线程宏 - >>在cider-repl中产生错误:

(-> "x..")

//  Unable to resolve symbol: -> in this context
Run Code Online (Sandbox Code Playgroud)

Art*_*ldt 6

当您在repl中创建新的命名空间并且尚未在其中定义任何内容时,会发生这种情况.所以clojure.core函数的别名尚未建立:

首先创建一个新的空白命名空间:

user> (in-ns 'i-dont-exist-yet)
#namespace[i-dont-exist-yet]
Run Code Online (Sandbox Code Playgroud)

然后尝试使用线程宏(或clojure.core中的任何内容):

i-dont-exist-yet> (-> 1)
CompilerException java.lang.RuntimeException: Unable to resolve symbol: -> in this context, compiling:(*cider-repl api*:47:18) 
Run Code Online (Sandbox Code Playgroud)

它无法->在当前命名空间中查找符号,但如果您告诉它明确使用哪个命名空间,它就会起作用:

i-dont-exist-yet> (clojure.core/-> 1)
1
Run Code Online (Sandbox Code Playgroud)

clojure.core中有一个便利功能,它将为你的新namespce添加所有预期的引用.当您从ns顶部带有宏的文件创建命名空间时,您不需要这样做,因为ns这样做(以及其他有用的事情):

i-dont-exist-yet> (clojure.core/refer-clojure)
nil
i-dont-exist-yet> (-> 1)
1
Run Code Online (Sandbox Code Playgroud)