Why is (quote '“foo”) valid syntax in Scheme?

↘锁芯ラ 提交于 2019-12-14 04:03:43

问题


Why does (quote '"foo") go through the Scheme interpreter? It should be syntactically redundant or wrong based on how expressions are constructed in Scheme. quote is used whenever one wants to use a symbol without Scheme thinking it's a variable and strings aren't valid symbols so why is the abbreviation for the quote operator valid when prefixed to strings? Oddly enough (quote '"foo") returns (quote "foo"). Redundancy?

Another strange experiment (symbol? '"foo") is evaluated to #f so that proves that quoted strings still aren't symbols (if the quote works that way in a statement). So, is the ' ignored on strings or does it serve some purpose elsewhere? I am using Chicken Scheme.

Somewhat trivial but kinda mind boggling at the same time.


回答1:


As stated in the specification:

(quote <datum>) evaluates to the datum value represented by (see section 4.3). This notation is used to include constants.

The above doesn't exclude the quotation of strings, in fact one of the examples in that section is this one:

'"abc" => "abc"

It follows that this is also valid:

''"abc" => ''"abc"


来源:https://stackoverflow.com/questions/15481508/why-is-quote-foo-valid-syntax-in-scheme

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