为什么 Scheme 中的 (quote ''foo') 语法是有效的? [英] Why is (quote '"foo") valid syntax in Scheme?

查看:53
本文介绍了为什么 Scheme 中的 (quote ''foo') 语法是有效的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么 (quote '"foo") 要通过 Scheme 解释器?根据 Scheme 中表达式的构造方式,它在语法上应该是多余的或错误的.quote 用于任何时候想要使用符号而 Scheme 不认为它是一个变量而字符串不是 有效符号 那么为什么 quote 运算符的缩写在前缀为字符串?奇怪的是 (quote '"foo") 返回 (quote "foo").冗余?

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?

另一个奇怪的实验 (symbol? '"foo") 被评估为 #f 从而证明引用的字符串仍然不是符号 (如果引用在声明中以这种方式工作).那么,字符串上的 ' 是被忽略的还是在其他地方有某种用途?我正在使用鸡肉计划.

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.

有点微不足道,但同时又有点令人难以置信.

推荐答案

规范:

(quote ) 计算为由(参见第 4.3 节)表示的数据值.此表示法用于包含常量.

(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"

因此这也是有效的:

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

这篇关于为什么 Scheme 中的 (quote ''foo') 语法是有效的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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