[plt-scheme] Uppercase symbol handling

From: Jens Axel Søgaard (jensaxel at soegaard.net)
Date: Wed Feb 2 14:39:34 EST 2005

Paulo Jorge de Oliveira Cantante de Matos wrote:

> I usually use everything lowercase by default but I'm reading
> xml from the net so some symbol just show up as uppercase. I'm
> getting somewhat confused with handling some issues. Can
> someone explain the behaviour of the next 2 interactions? (with
> module language enabled)
> (module test mzscheme
> 
>   (read-case-sensitive #t)

At runtime this will make READ case sensitive. This won't
affect the compiler.

>   (define test
>     (lambda (l)
>       (if (eq? (car l) 'Item)

The 'Item is at compile time internalized to 'item.

>           (display "OK")
>           (display "Not OK"))))
> 
>   (define test1
>     (lambda (l)
>       (if (eq? (car l) 'item)
>           (display "OK")
>           (display "Not OK"))))
> 
>   )
> 
>>(test '(Item a b c))
> 
> Not OK
> 
>>(test1 '(Item a b c))
> 
> Not OK

If you want to keep the original spelling of a symbol,
you can use pipes to enclose the symbol. Alternatively
you can tell the compiler that it should be case sensitive
by prefixing the expression with #cs.


(module test mzscheme
   (provide (all-defined))

   (define test2
     (lambda (l)
       (if (eq? (car l) '|Item|)
           (display "OK")
           (display "Not OK"))))

   #cs(define test3
        (lambda (l)
          (if (eq? (car l) 'Item)
              (display "OK")
              (display "Not OK")))))

 > (require test)
 > (test2 '(Item))
OK
 > (test3 '(Item))
OK

If you want the compiler to treat the whole module
in a case sensitive manner, use #cs(module ...).

If I recall correctly, the new v299 uses the
case sensitive mode as default.

-- 
Jens Axel Søgaard




Posted on the users mailing list.