4.10 引述:quote'

+The Racket ReferenceLiterals: quote and #%datum一节中也提供了quote的文档。

quote 形式产生一个常量:

(quote datum)

从技术上来说,datum 的语法可由任何能够被 read 函数解析为 单个元素的东西所指定。quote 形式的值与在向 read 给定 datum 时所产生的值相同。

datum 可以是符号、布尔值、数值、(字符或字节)串、字符、关键字、空列表,以及包含更多这类值的序对(或列表)、向量、散列表或盒子。

例如:
> (quote apple)

'apple

> (quote #t)

#t

> (quote 42)

42

> (quote "hello")

"hello"

> (quote ())

'()

> (quote ((1 2 3) #("z" x) . the-end))

'((1 2 3) #("z" x) . the-end)

> (quote (1 2 . (3)))

'(1 2 3)

如上面的最后一个例子所示,datum 不必匹配值的一般化打印形式。 datum 不能是以 #< 开头的打印表示,因此它不能是 #<void>#<undefined> 或一个过程。

quote 很少用于 datum 为布尔值、数值或字符串本身的情况, 因为这些值的打印形式已经被用作常量了。quote 形式更常用于符号和列表, 因为它们在未被引述时可以有别的意思(如标识符、函数调用等等)。

表达式

'datum

(quote datum)

的简写形式,我们几乎总是使用该简写而非 quote。此简写甚至可以在 datum 中应用,因此它可以处理包含 quote 的列表。

+The Racket ReferenceReading Quotes一节中提供了关于' 简写形式的更多信息。

例如:
> 'apple

'apple

> '"hello"

"hello"

> '(1 2 3)

'(1 2 3)

> (display '(you can 'me))

(you can (quote me))