[plt-scheme] String equality and other questions
At Tue, 23 Sep 2008 21:25:26 -0700 (PDT), Deep wrote:
> While writing a game in scheme I recently ran into an issue where
> using equal? to compare strings would wait on the equality test and
> hog the cpu 60-70% of the time. Oddly enough it worked sometimes. I
> looked through my code suspecting a recursive call gone amuck but
> eventually narrowed the issue down to this call. I had unfortunately
> run into http://www.federated.com/~jim/schintro-v14/schintro_102.html
> when searching for "scheme string equality" and used equal?.
>
> Once I looked again and changed the code to use string=? things work
> just fine. I wanted to know what does equal? do when used against
> strings. Why does it work sometimes and why does it just hang on other
> occasions?
As Eli says, that's a surprising result. The `equal?' function is
commonly used on strings, and assuming that you're using a language
like `scheme/base', R5RS, or R6RS (all the same `equal?'), then
`equal?' fairly quickly determines when it's given strings and then
does the same thing as `string=?'.
If your program is something that you can send to me, then I'm
interested to try it myself (with `equal?' in place of `string=?').
Matthew