[plt-scheme] Pointers and hashing

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Sat Jan 16 09:22:35 EST 2010

At Sat, 16 Jan 2010 01:10:26 +0100, Thomas Chust wrote:
> I'm coding a Scheme interface to a C library and have used structures
> containing a native pointer plus some additional cached information as
> wrappers for a certain type of native objects. I want these structures
> to compare equal? if they contain the same pointer, so I set a
> prop:equal+hash property on the structure type but now I wonder how to
> implement the hashing functions that, of course, should be consistent
> with the equality predicate: Pointers to the same address don't
> necessarily compare equal? and I didn't find any predefined procedure to
> compute a hash code in agreement with ptr-equal?.
> Is there any sane way to compute such a hash code or do I really have to
> write the pointer into some memory cell, read it back as an integer and
> work with that value? It feels so C, I don't want to do that ;-)

I don't have any better idea, but I note that the `cast' function from
`scheme/foreign' will do the memory-cell read and write for you.

Posted on the users mailing list.