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 在ns定义中使用引号括起来表示需要_Clojure - Fatal编程技术网

Clojure 在ns定义中使用引号括起来表示需要

Clojure 在ns定义中使用引号括起来表示需要,clojure,Clojure,当使用require时,我需要在左括号前使用引号,但当我使用ns with:require时,我不必使用引号。为什么呢 (ns foo) (ns user) (require '[foo :as f]) ;; quote (ns bar (:require [foo :refer :all])) ;; no quote 我知道引号不能计算括号前面的表达式,但我不完全确定为什么括号前面需要引号,因为它们不是表达式,所以不应该计算任何内容。您可以要求符号不绑定在您的命

当使用require时,我需要在左括号前使用引号,但当我使用ns with:require时,我不必使用引号。为什么呢

(ns foo)
(ns user)
(require '[foo :as f])                ;; quote
(ns bar (:require [foo :refer :all])) ;; no quote

我知道引号不能计算括号前面的表达式,但我不完全确定为什么括号前面需要引号,因为它们不是表达式,所以不应该计算任何内容。

您可以
要求
符号不绑定在您的命名空间中-向量前面的
(或仅使用
(要求使用“clojure.string”)
这样的示例中的
(不使用任何选项)可防止因使用未绑定的符号而导致的错误


ns
是一个宏,它使用其主体的
:require
部分来构建对
require
的调用。允许宏决定对哪个输入进行求值,而不是将哪个输入作为文本输入,因此您不必对
ns
宏使用

[foo:reference:all]
[foo:as f]
都是表达式,即使
42
是一个表达式(在本例中当然是自评估的)对不起,我还是不去尝试。[1 2 3]返回[1 2 3],但(1 2 3)返回一个ClassCastException。我需要“(1 2 3)那么为什么不在数组中使用引号呢?数组表达式似乎总是返回一个数组。为什么我必须在require中使用引号呢?因为在引用表达式时,该表达式中的符号不会被计算,
“no-thing
返回一个有效的符号,
no-thing
将抛出一个错误r(除非你之前用def或let等绑定了该符号)。我正在更新我下面的答案,以包含基本原理的这一部分,我有点跳过了。谢谢。绑定部分是我缺少的。