Scheme 符号区分大小写 [英] Case sensitivity in Scheme symbols

查看:119
本文介绍了Scheme 符号区分大小写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,Scheme 中的符号不​​区分大小写 - 即 (eq? 'Hello 'hello) 评估为 #t(因为两者都由符号'hello,并且scheme具有两个同名符号是同一个对象的属性).然而,这对我来说似乎并非如此,事情似乎是区分大小写的,无论我尝试使用 #lang scheme#lang racket 还是#lang eopl 风格的 Scheme.有没有人知道为什么?

解决方案

简短/简单的答案:区分大小写因标准而异,并且您使用的特定实现具有区分大小写的标识符.但这些信息孤立地可能不是很有帮助.那么到底哪里出了问题?

鉴于您提到了 #langs,很明显您使用的是 Racket.Racket 是 Scheme 的后代,但它不符合任何现有的 Scheme 标准.然而,Racket 是可扩展的——它可以支持多种语言,甚至是用户定义的语言——所以 Racket 支持不同的 Scheme 迭代.

哪些方案区分大小写?

在撰写本文时,Scheme 标准存在三个相关版本:R5RS、R6RS 和 R7RS.

  • R5RS 始终不区分大小写.
  • R6RS 始终区分大小写.
  • R7RS 默认区分大小写,但 #!fold-case 指令或 include-ci 形式可以禁用区分大小写.

如您所见,这个问题确实不明确:在过去的三个标准中,它并没有保持一致.事实上,鉴于默认情况下 R7RS 和 R6RS 都区分大小写,现在说 Scheme 区分大小写可能更准确.然而,虽然 R5RS 已经过时了很长时间,但它仍然作为许多书籍、解释器和编译器以及其他材料中使用的方案"继续存在,因此可能得出方案不区分大小写"的结论.

您使用的是哪种方案?

没有一个.也许令人困惑的是,即使 #lang scheme 也不是任何 Scheme 标准的实现.事实上,#lang scheme 是一种已弃用的语言,已被 #lang racket 完全取代(前者在 PLT Scheme 重命名为 Racket 之前就存在,很大程度上是为了减少关于其方案"不是实际方案实施的混淆).

那么,您可能会问,如何在 Racket 中获取实际的 Scheme?好吧,Racket 确实提供了各种 Scheme 标准的实现.#lang r5rs#lang r6rs 都是相关 Scheme 标准的内置实现.R7RS 实现可通过 r7rs 包以 #lang r7rs 的形式提供.

Racket 的所有语言都可以互操作,因此您选择的语言取决于您,尽管 RnRS 语言在 Racket 社区中往往未被使用(#lang racket 更有用 用于编写程序而不是任何 Scheme 实现),但如果您想编写在不同 Scheme 实现上运行的程序,它们会很有用.

From what I have read, symbols in Scheme are case insensitive - i.e. (eq? 'Hello 'hello) evalulates to #t (because both are represented by the symbol 'hello, and scheme has the property that two symbols with the same name are the same object). However, this doesn't seem to be the case for me, and things seem to be case-sensitive, whether I try using the #lang scheme, #lang racket or #lang eopl flavours of Scheme. Does anyone have any ideas why?

解决方案

The short/simple answer: case-sensitivity varies from standard to standard, and the particular implementations you were using have case-sensitive identifiers. But this information is probably not very helpful in isolation. So what went "wrong"?

Given that you mention #langs, it's clear you were using Racket. Racket is a descendant of Scheme, but it does not conform to any existing Scheme standard. However, Racket is extensible—it can support lots of languages, even user-defined ones—so different iterations of Scheme are supported by Racket.

Which Schemes are case-sensitive?

There are three relevant versions of the Scheme standard in existence at the time of this writing, R5RS, R6RS, and R7RS.

  • R5RS is always case-insensitive.
  • R6RS is always case-sensitive.
  • R7RS is case-sensitive by default, but the #!fold-case directive or the include-ci form can disable case-sensitivity.

As you can see, this issue really isn't clear-cut: it hasn't remained consistent over the past three standards. In fact, given that R7RS and R6RS are both case-sensitive by default, it might be more accurate to say that Scheme is case-sensitive now. However, while R5RS has been outdated for a long time, it continues to live on as "The Scheme" used in many books, interpreters and compilers, and other materials, hence the possible conclusion that "Scheme is case-insensitive."

Which Scheme were you using?

None of them. Perhaps confusingly, even #lang scheme isn't an implementation of any Scheme standard. In truth, #lang scheme is a deprecated language that has been completely supplanted by #lang racket (the former existed before PLT Scheme was renamed to Racket, much in part to reduce the confusion about its "Scheme" not being an actual Scheme implementation).

So, you may ask, how can you get actual Scheme inside of Racket? Well, Racket does provide implementations of the various Scheme standards. Both #lang r5rs and #lang r6rs are built-in implementations of the relevant Scheme standards. An R7RS implementation is available as #lang r7rs through the r7rs package.

All of Racket's languages can interoperate, so your language of choice is up to you, though the RnRS languages tend to go unused in the Racket community (#lang racket is much more useful for writing programs than any of the Scheme implementations), but they can be useful if you want to write programs that run on different Scheme implementations.

这篇关于Scheme 符号区分大小写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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