Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Case sensitivity in Scheme symbols

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?

like image 820
Lord Cat Avatar asked Dec 15 '22 10:12

Lord Cat


2 Answers

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.

like image 154
Alexis King Avatar answered Jan 30 '23 20:01

Alexis King


When I run this program:

#lang r5rs

(display (equal? 'abc 'ABC))

the result is #t. So you are getting case-insensitivity here.

However, if you then type

(equal? 'abc 'ABC)

in the interactions window, you get #f. I think I would probably consider this a bug, but it might be a difficult one to fix.

like image 28
John Clements Avatar answered Jan 30 '23 22:01

John Clements