为什么 Racket 解释器之前用撇号写列表?

Why does the Racket interpreter write lists with an apostroph before?

为什么写的是'(1 2 3)而不是(1 2 3)?

> (list 1 2 3)
'(1 2 3)

Racket 的默认打印机将一个值打印为一个表达式,该表达式将计算为等效值(如果可能)。它尽可能使用quote(缩写为');如果一个值包含一个不可引用的数据结构,它会使用构造函数来代替。例如:

> (list 1 2 3)
'(1 2 3)
> (list 1 2 (set 3))   ;; sets are not quotable
(list 1 2 (set 3))

大多数 Lisps 和 Schemes 使用 write 函数来打印值。您可以使用 print-as-expression 参数将 Racket 的打印机更改为 write 模式,如下所示:

> (print-as-expression #f)
> (list 1 2 3)
(1 2 3)

有关详细信息,请参阅 the docs on the Racket printer