Question

R5RS 6.3.3 says

(eq? 'bitBlt (string->symbol "bitBlt")) ==>  #f

Does this mean that

(eq? 'bitBlt (string->symbol (symbol->string 'bitBlt))) ==> #f?

elk returns #t!

R5RS also says

(string->symbol "mISSISSIppi") ==> the symbol with name "mISSISSIppi"

(presumably this means 'mISSISSIppi)

and

(symbol->string 'Martin) ==> "martin"

meaning that symbol->string returns a string in standard case (lowercase in this example).

So if I expand my second example

(symbol->string 'bitBlt) ==> "bitblt"
(string->symbol (symbol->string 'bitBlt)) ==> 'bitblt

and therefore

(eq? 'bitBlt (string->symbol (symbol->string 'bitBlt))) ==> #t

because symbols are case insensitive from R5RS

(eq? 'mISSISSIppi 'mississippi) ==> #t

So if I expand my original question

(string->symbol "bitBlt") ==> 'bitblt

and therefore

(eq? 'bitBlt (string->symbol "bitBlt")) ==>  #t

Right? But R5Rs says #f!

Where am I going wrong here?

Why would this behaviour be specified?

Ref:

http://people.csail.mit.edu/jaffer/r5rs_8.html#SEC49

http://bugs.call-cc.org/browser/numbers/r4rstest.scm?rev=1 line 468

Actual session example:

3> (display 'bitBlt)
bitblt
3> (display (string->symbol "bitBlt"))
bitBlt
3> (eq? 'bitBlt (string->symbol "bitBlt"))
#f
3> (eq? 'bitblt (string->symbol "bitBlt"))
#f
3> (eq? 'bitblt (string->symbol "bitblt"))
#t
3> (eq? 'bitBlt (string->symbol (symbol->string 'bitBlt)))
#t
3> (eq? 'mISSISSIppi 'mississippi)
#t
Was it helpful?

Solution

The example you quote "assume[s] that the implementation's standard case is lower case". That means that the expression 'bitBlt actually expands to the symbol bitblt. Symbols aren't actually case-insensitive; read may normalize case.

string->symbol's semantics differ from that of read and the procedure may return a mixed-case symbol:

This procedure can create symbols with names containing special characters or letters in the non-standard case, but it is usually a bad idea to create such symbols because in some implementations of Scheme they cannot be read as themselves.

In your implementation, string->symbol seems to normalize case as well. Check the output of

(display 'bitBlt)
(display (string->symbol "bitBlt"))

to be sure.

(My previous answer was wrong.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top