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

拟墨画扇 提交于 2021-01-28 04:49:02

问题


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

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

回答1:


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))

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)

See the docs on the Racket printer for more information.



来源:https://stackoverflow.com/questions/36508406/why-does-the-racket-interpreter-write-lists-with-an-apostroph-before

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!