[plt-scheme] Switching to Scheme

From: Danny Yoo (dyoo at hkn.eecs.berkeley.edu)
Date: Mon Jul 3 10:50:58 EDT 2006

>> mzscheme's hash tables are eq? by default.  We have to go out of our 
>> way to make them work through equal?  See the 'equal flag passing 
>> option in:
>
> I understand that eq? is the fastest way to compare, but it offers very 
> little guarantee that it makes meaningful comparisons.  According to the 
> standard, there's even no guarantee that (eq? 2 2) will return true. 
> So which things are safe to use as keys for the eq? style hashtable?


Hi Mark,

According to r5rs:

http://download.plt-scheme.org/doc/350/html/r5rs/r5rs-Z-H-9.html#%_idx_220

I usually use eq? hashtables for doing object caching, and for most other 
situations, I'll use equal? ones.  Here's an example of a hash table from 
strings to strings:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> (define my-mapping (make-hash-table 'equal))
> (hash-table-put! my-mapping "h" "hello")
> (hash-table-put! my-mapping "w" "world")
> (hash-table-get my-mapping "h")
"hello"
> (hash-table-get my-mapping "w")
"world"
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;



> Can strings and/or lists be easily converted into something that can be 
> compared with eq?

Strings and lists can be compared with eq?.  The thing is that it'll be a 
check on object identity.

Think of Python 'is' comparison operator. It's the same thing with eq?. 
The analogy is:

     Python     Scheme
     ==         equal?
     is         eq?



Best of wishes!


Posted on the users mailing list.