[plt-scheme] 'equal hashes don't survive serialization

From: Daniel Yoo (dyoo at cs.wpi.edu)
Date: Sun Feb 25 16:43:23 EST 2007


> When I use the serialize.ss library to serialize my hash tables that 
> were created to use equal? to compare keys, the hash tables deserialize 
> with eq? as the key-comparison mode.  How do I avoid this?  With eq? as 
> the key-comparison mode, a look up with a key as simple as '(2) won't 
> work, I found.

Hi George,


That's unusual!  Let me check something.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
dyoo at dyoo-desktop:~$ local/plt-360/bin/mzscheme
Welcome to MzScheme version 360, Copyright (c) 2004-2006 PLT Scheme Inc.
> (require (lib "serialize.ss"))
>
> (hash-table? (deserialize (serialize (make-hash-table 'equal))) 'equal)
#t
>
> (hash-table? (deserialize (serialize (make-hash-table))) 'equal)
#f
>
> (define ht (make-hash-table 'equal))
> (hash-table-put! ht '(2) "two")
> (define refreshed-ht (deserialize (serialize ht)))
> (hash-table-get refreshed-ht (cons 2 '()))
"two"
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


serialize.ss should preserve the flags that the hash table was constructed 
with.  I did a scan through the source code, and didn't see anything 
unusual.  The example above looks like it works as expected.


There might be something going on here, since you're running into 
problems.  Do you have an example we can test out to see if we can 
duplicate the behavior you're seeing?


Best of wishes!


Posted on the users mailing list.