[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.3 Case-sensitivity

Historically, most Lisp-family languages are case-insensitive for symbols. Scheme is no exception and R5RS defines symbols are read in case-insensitive way. (Note that symbols are case-sensitive internally even in R5RS Scheme; case-insensitivity is about readers.)

However, nowadays programming is hardly completed in one language. When you have to interact with other languages that distinguishe uppercase and lowercase characters, it is desirable that Scheme distinguishes them as well.

So Gauche has two modes in reading and writing symbols. By default, Gauche reads and writes symbols in case-sensitive manner. This behavior doesn't conform R5RS.

; In case-sensitive mode (default)
(eq? 'a 'A) => #f  ; #t in R5RS
(symbol->string 'ABC) => "ABC"
(symbol->string 'abc) => "abc"
(display (string->symbol "ABC")) => writes ABC
(display (string->symbol "abc")) => writes abc

You can make Gauche case-insensitive by giving -fcase-fold command-line option to the gosh interpreter (See section 3.1 Invoking Gosh). In this mode, the reader folds uppercase characters in symbols to lowercase ones. If a symbol name contains uppercase characters, it is written out using |-escape (See section 6.5 Symbols).

; In case-insensitive mode (with -fcase-fold option)
(eq? 'a 'A) => #t
(symbol->string 'ABC) => "abc"
(symbol->string 'abc) => "abc"
(display (string->symbol "ABC")) => writes |ABC|
(display (string->symbol "abc")) => writes abc

Right now, there's no way to switch these two modes back and forth inside the intepreter; an API will be provided in the later versions.

This document was generated by Ken Dickey on November, 28 2002 using texi2html