为什么 Racket 解释器之前用撇号写列表? [英] Why does the Racket interpreter write lists with an apostroph before?

查看:45
本文介绍了为什么 Racket 解释器之前用撇号写列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Why is '(1 2 3) written instead of (1 2 3) ?

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

推荐答案

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

Racket's default printer prints a value as an expression that would evaluate to an equivalent value (when possible). It uses quote (abbreviated ') when it can; if a value contains an unquotable data structure, it uses constructor functions instead. For example:

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

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

Most Lisps and Schemes print values using the write function instead. You can change Racket's printer to write mode using the print-as-expression parameter, like this:

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

有关详细信息,请参阅Racket 打印机上的文档.

See the docs on the Racket printer for more information.

这篇关于为什么 Racket 解释器之前用撇号写列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆